-
Notifications
You must be signed in to change notification settings - Fork 1
/
qwilr-logger.js
87 lines (84 loc) · 2.49 KB
/
qwilr-logger.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
This is a simple logging utility for Qwilr.
With a couple of verbs / states.
Like 'at' for describing where in the codebase we are.
And 'success' / 'error' / 'note' etc.
We can use it like normal log: log 'Something'
Or we can use the log.at "Some Function"
Loggers also have names.
*/
var _,
__slice = [].slice;
_ = require("lodash");
module.exports = function(options) {
var colors, log, logName, stubFn, stubs, _i, _len;
logName = _.isString(options) ? options + " " : options.name != null ? options.name + " " : "";
if (options.debug == null) {
options.debug = true;
}
if ((options != null ? options.debug : void 0) === false) {
log = function() {};
stubs = ['at', 'doing', 'say', 'success', 'error', 'note'];
for (_i = 0, _len = stubs.length; _i < _len; _i++) {
stubFn = stubs[_i];
log[stubFn] = function() {};
}
return log;
}
colors = require('colors/safe');
log = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (process.env.SILENT_LOGGING != null) {
return;
}
args.unshift(colors.grey(logName));
return console.log.apply(console, args);
};
log.warn = function() {
var data;
data = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return log(colors.yellow(data));
};
log.at = function(data) {
var border;
if (process.env.SILENT_LOGGING != null) {
return;
}
console.log("");
border = Array(data.length + 7).join('-');
log(colors.magenta(border));
log(colors.magenta("AT: ", data));
return log(colors.magenta(border));
};
log.doing = function() {
var data;
data = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return log(colors.blue(data));
};
log.say = function() {
var data;
data = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return log(data);
};
log.error = function() {
var data;
data = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
log(colors.red("ERROR: ", data));
log(colors.red("------------------------------"));
if (options.errorHandler != null) {
return options.errorHandler(options.name + ": " + data);
}
};
log.success = function() {
var data;
data = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return log(colors.green(data));
};
log.note = function() {
var data;
data = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return log(colors.cyan(data));
};
return log;
};