Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
/*
2
* custom-timestamp-test.js: Test function as timestamp option for transport `{ timestamp: function () {} }`
3
*
4
* (C) 2011 Charlie Robbins, Tom Shinnick
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
events = require('events'),
11
fs = require('fs'),
12
path = require('path'),
13
vows = require('vows'),
14
winston = require('../lib/winston'),
15
helpers = require('./helpers');
16
17
function assertTimestamp (basename, options) {
18
var filename = path.join(__dirname, 'fixtures', 'logs', basename + '.log');
19
20
try { fs.unlinkSync(filename) }
21
catch (ex) { }
22
23
return {
24
topic: function () {
25
options.filename = filename;
26
var transport = new (winston.transports.File)(options);
27
28
// We must wait until transport file has emitted the 'flush'
29
// event to be sure the file has been created and written
30
transport.once('flush', this.callback.bind(this, null, filename));
31
transport.log('info', 'When a fake tree falls in the forest...', null, function () {});
32
},
33
"should log with the appropriate timestamp": function (_, filename) {
34
var data = fs.readFileSync(filename, 'utf8');
35
assert.isNotNull(data.match(options.pattern));
36
}
37
}
38
}
39
40
vows.describe('winston/transport/timestamp').addBatch({
41
"When timestamp option is used": {
42
"with file transport": {
43
"with value set to false": assertTimestamp('noTimestamp', {
44
pattern: /^info\:/,
45
json: false,
46
timestamp: false
47
}),
48
"with value set to true ": assertTimestamp('defaultTimestamp', {
49
pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/,
50
json: false,
51
timestamp: true
52
}),
53
"and function value": assertTimestamp('customTimestamp', {
54
pattern: /^\d{8}\./,
55
json: false,
56
timestamp: function () {
57
return '20110803.171657';
58
}
59
})
60
}
61
}
62
}).export(module);
63