Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ The following configuration options are available.
// should the value of $location.absUrl() be sent as a "url" key in the
// message object that's sent to loggly? Default is false.
.includeUrl( false )

// should the value of $window.navigator.userAgent be sent as a "userAgent" key in the
// message object that's sent to loggly? Default is false.
.includeUserAgent( false )

// should the current timestamp be included? Default is false.
.includeTimestamp( false )
Expand All @@ -112,6 +116,21 @@ The following configuration options are available.
// keep sending messages to Loggly in production without also sending them
// to the console. Default is true.
.logToConsole( true )

// Custom labels for standard log fields. Use this to customize your log
// message format or to shorten your logging payload. All available labels
// are listed in this example.
.labels({
col: 'c',
level: 'lvl',
line: 'l',
logger: 'lgr',
message: 'msg',
stack: 'stk',
timestamp: 'ts',
url: 'url',
userAgent: 'userAgent'
})

```

Expand Down
32 changes: 32 additions & 0 deletions angular-loggly-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
var extra = {};
var includeCurrentUrl = false;
var includeTimestamp = false;
var includeUserAgent = false;
var tag = null;
var sendConsoleErrors = false;
var logToConsole = true;
var loggingEnabled = true;
var labels = {};

// The minimum level of messages that should be sent to loggly.
var level = 0;
Expand All @@ -49,6 +51,15 @@
return extra;
};

this.labels = function(l) {
if (angular.isObject(l)) {
labels = l;
return self;
}

return labels;
};

this.inputToken = function ( s ) {
if (angular.isDefined(s)) {
token = s;
Expand Down Expand Up @@ -85,6 +96,15 @@
return includeTimestamp;
};

this.includeUserAgent = function (flag) {
if (angular.isDefined(flag)) {
includeUserAgent = !!flag;
return self;
}

return includeUserAgent;
};

this.inputTag = function (usrTag){
if (angular.isDefined(usrTag)) {
tag = usrTag;
Expand Down Expand Up @@ -159,6 +179,7 @@
}

//TODO we're injecting this here to resolve circular dependency issues. Is this safe?
var $window = $injector.get( '$window' );
var $location = $injector.get( '$location' );
//we're injecting $http
var $http = $injector.get( '$http' );
Expand All @@ -175,6 +196,10 @@
sentData.timestamp = lastLog.toISOString();
}

if( includeUserAgent ) {
sentData.userAgent = $window.navigator.userAgent;
}

//Loggly's API doesn't send us cross-domain headers, so we can't interact directly
//Set header
var config = {
Expand All @@ -184,6 +209,13 @@
withCredentials: false
};

// Apply labels
for (var label in labels) {
if (label in sentData) {
sentData[labels[label]] = sentData[label];
delete sentData[label];
}
}

//Ajax call to send data to loggly
$http.post(buildUrl(),sentData,config);
Expand Down
2 changes: 1 addition & 1 deletion angular-loggly-logger.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion angular-loggly-logger.min.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading