UNPKG

1.16 kBJavaScriptView Raw
1'use strict'
2
3
4 function Logger(options) {
5 this.$Logger_options = options
6 this.$Logger_count = 0
7 this.$Logger_stack = {}
8 }
9
10 Logger.prototype.log=function(message, func) {
11 var result
12
13 if (process.env.NODE_ENV !== 'production' && this.$Logger_options.debug) {
14 this.$Logger_start(message)
15 result = func()
16 this.$Logger_stop(message)
17 return result
18 }
19 return func()
20 };
21
22 Logger.prototype.$Logger_start=function(message) {
23 var indentation = this.$Logger_indent()
24 var now = new Date()
25
26 this.$Logger_stack[message] = now
27
28 console.log(("[" + now.toISOString() + "] " + indentation + "Starting " + message + "..."))
29 };
30
31 Logger.prototype.$Logger_stop=function(message) {
32 var indentation = this.$Logger_unindent()
33 var now = new Date()
34 var elapsed = now - this.$Logger_stack[message]
35
36 console.log(("[" + now.toISOString() + "] " + indentation + "Finished " + message + " after " + elapsed + " ms"))
37 };
38
39 Logger.prototype.$Logger_indent=function() {
40 return Array(++this.$Logger_count).join(' ')
41 };
42
43 Logger.prototype.$Logger_unindent=function() {
44 return Array(this.$Logger_count--).join(' ')
45 };
46
47
48module.exports = Logger
\No newline at end of file