-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
86 lines (68 loc) · 2.13 KB
/
test.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
var cclog = require('./cclog');
cclog.useColors = true;
var fs = require('fs')
cclog.inspect('33', 33, "33", [33]);
cclog.replace();
console.log('replace with cclog');
console.log('this is log');
console.log({object: 'this is object'});
console.info('this is info');
console.warn('this is warn');
console.error('this is error');
console.log('console.trace')
console.trace({msg: 'this is an object'});
console.trace(new Error('this is an error'));
console.dir({obj: 'dir obj'})
// this will error
fs.mkdir(__dirname + '/test.js', cclog.ifError);
// test ifError for EventEmitter
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
emitter.on('error', cclog.ifError);
var err = new Error('error from emitter');
emitter.emit('error', err);
// simple callback new Error
function foo(callback) {
var err = new Error('error from somewhere');
callback(err);
}
foo(cclog.ifError);
// intercept
function bar(callback) {
callback(null, 1, 2, 3);
}
bar(cclog.intercept('The bar result'));
foo(cclog.intercept('The bar result', function(err, data) {
cclog('done', err, data);
}));
cclog.restore();
console.log('');
console.log('restore to origin console');
console.log('this is log');
console.info('this is info');
console.warn('this is warn');
console.error('this is error');
cclog('cclog');
cclog.log('cclog.log');
cclog.info('cclog.info');
cclog.error('cclog.error', new Error('A fake error occused'));
cclog.warn('cclog.warn');
cclog.useColors = false;
cclog('cclog');
cclog.log('cclog.log');
cclog.info('cclog.info');
cclog.error('cclog.error', 'just', {err: 1});
cclog.error('cclog.error', new Error('A fake error occused'));
cclog.warn('cclog.warn');
cclog.setLevel('warn');
cclog.log('should not see this');
cclog.debug('should not see this');
cclog.info('should not see this');
cclog.warn('should see this');
cclog.error('should see this');
var logger = cclog.logger(__dirname + '/log.txt');
logger.log('logger.log');
logger.info('logger.info', 0, 'foo', null, 'bar', undefined);
logger.error('logger.error', new Error('A fake error'), null, 'foo', undefined);
cclog.setLevel('info');
cclog('====== ALL DONE ======');