Skip to content

Commit 6bbe769

Browse files
committed
restrict message logging based on additional config property
1 parent 08b1643 commit 6bbe769

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ The config object to be passed to each service has the following properties:
1717
- none: perform no logging
1818
- REMOTE_LOGGING_ENDPOINT: the full URL to the endpoint where log messages are sent via AJAX POST
1919
- REMOTE_ERROR_REPORT_ENDPOINT: the full URL to the endpoint where user error reports will be sent via AJAX POST
20+
- LOGGING_LEVEL (can be debug|error)
21+
- debug: log both debug and error messages
22+
- error: only log error messages (debug messages are not logged)
2023

2124
The config object should be declared as an AngularJS constant named LOGGING_CONFIG.

js/logging.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,24 @@ loggingModule.factory(
113113
}
114114
},
115115
debug: function(message){
116-
if (LOGGING_CONFIG.LOGGING_TYPE !== 'none') {
117-
$log.log.apply($log, arguments);
118-
}
116+
if (LOGGING_CONFIG.LOGGING_LEVEL !== 'error') {
117+
if (LOGGING_CONFIG.LOGGING_TYPE !== 'none') {
118+
$log.log.apply($log, arguments);
119+
}
119120

120-
// check if the config says we should log to the remote, and also if a remote endpoint was specified
121-
if (LOGGING_CONFIG.LOGGING_TYPE === 'remote' && LOGGING_CONFIG.REMOTE_LOGGING_ENDPOINT) {
122-
$.ajax({
123-
type: "POST",
124-
url: LOGGING_CONFIG.REMOTE_LOGGING_ENDPOINT,
125-
contentType: "application/json",
126-
data: angular.toJson({
127-
url: $window.location.href,
128-
message: message,
129-
type: "debug"
130-
})
131-
});
121+
// check if the config says we should log to the remote, and also if a remote endpoint was specified
122+
if (LOGGING_CONFIG.LOGGING_TYPE === 'remote' && LOGGING_CONFIG.REMOTE_LOGGING_ENDPOINT) {
123+
$.ajax({
124+
type: "POST",
125+
url: LOGGING_CONFIG.REMOTE_LOGGING_ENDPOINT,
126+
contentType: "application/json",
127+
data: angular.toJson({
128+
url: $window.location.href,
129+
message: message,
130+
type: "debug"
131+
})
132+
});
133+
}
132134
}
133135
}
134136
});

0 commit comments

Comments
 (0)