-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngModularLog.js
33 lines (31 loc) · 1.42 KB
/
ngModularLog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
angular.module("aanimals.services.modular-log", []).
factory("ModularLog", function() {
return function(label) {
var _label = label + ": ";
return function(message, level) {
// If no console, can't log anything.
// Also allow you to silence output e.g. during tests
if (window.console && !window.console.silenced) {
// If level not defined, use 'console.log'
if (!level) {
level = "log";
}
// Why are you logging functions? But okay.
if (typeof message === "function") {
message = message + "";
}
// Convert objects to JSON.
if (typeof message === "object") {
message = JSON.stringify(message);
}
if (typeof window.console[level] === "function") {
// Try and log to the given custom log level
window.console[level](_label + message);
} else if (typeof window.console.log === "function") {
// If no custom log, just log to 'console.log'
window.console.log(level.toUpperCase() + " " + _label + message);
}
}
};
};
});