-
-
Save liveweird/14e04592c05a7a746dd9 to your computer and use it in GitHub Desktop.
Angular.js service used to send buffered client-side logs to the server-side Web API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
nebulaApp.controller('nebulaAppCtrl', | |
function($scope, $rootScope, $location, ...) { | |
// ... | |
$scope.$on("$routeChangeSuccess", function (angularEvent, current, previous) { | |
$scope.$emit("log:nebula", "Route changed: [" + $location.path() + "]"); | |
//... | |
}); | |
$rootScope.$on("log:nebula", function (e, data) { | |
nebulaLogSvc.log(data, ...); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
nebulaApp.service('nebulaLogSvc', ['$http', 'NEBULA_URL', function($http, nebulaUrl) { | |
var logBufferLength = 60; | |
var logBufferCpty = 10; | |
var idx = 1; | |
var apiLogger = Rx.Observer.create(function(entries) { | |
idx = idx + 1; | |
$http.post('' + nebulaUrl + 'api/Nebula/Log', | |
{ | |
id: idx, | |
entries: entries | |
} | |
); | |
}); | |
var loggedEvents = new Rx.Subject(); | |
loggedEvents.bufferWithTimeOrCount(logBufferLength * 1000, logBufferCpty) | |
.filter(function (array) { | |
return (array.length > 0); | |
}) | |
.subscribe(apiLogger); | |
function LogEntry(message, loginName) { | |
idx = idx + 1; | |
this.id = idx; | |
this.timeStamp = moment().toJSON(); | |
this.message = message; | |
this.loginName = loginName; | |
}; | |
this.log = function(message, loginName) { | |
loggedEvents.onNext(new LogEntry(message, loginName)); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment