logger-test.js
2.65 KB
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
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
vows = require('vows'),
fmonitor = require('../../lib');
var fixturesDir = path.join(__dirname, '..', 'fixtures');
function checkLogOutput(file, stream, expectedLength) {
var output = fs.readFileSync(path.join(fixturesDir, file), 'utf8'),
lines = output.split('\n').slice(0, -1);
assert.equal(lines.length, expectedLength);
lines.forEach(function (line, i) {
assert.equal(lines[i], stream + ' ' + (i % 10));
});
}
vows.describe('forever-monitor/plugins/logger').addBatch({
'When using the logger plugin': {
'with custom log files': {
topic: function () {
var that = this,
outlogs,
errlogs,
monitor;
monitor = new fmonitor.Monitor(path.join(fixturesDir, 'logs.js'), {
max: 1,
silent: true,
outFile: path.join(fixturesDir, 'logs-stdout.log'),
errFile: path.join(fixturesDir, 'logs-stderr.log')
});
monitor.on('exit', function () {
setTimeout(that.callback, 2000);
});
monitor.start();
},
'log files should contain correct output': function (err) {
checkLogOutput('logs-stdout.log', 'stdout', 10);
checkLogOutput('logs-stderr.log', 'stderr', 10);
}
},
'with custom log files and a process that exits': {
topic: function () {
var monitor = new fmonitor.Monitor(path.join(fixturesDir, 'logs.js'), {
max: 5,
silent: true,
outFile: path.join(fixturesDir, 'logs-stdout-2.log'),
errFile: path.join(fixturesDir, 'logs-stderr-2.log')
});
monitor.on('exit', this.callback.bind({}, null));
monitor.start();
},
'logging should continue through process restarts': function (err) {
checkLogOutput('logs-stdout-2.log', 'stdout', 50);
checkLogOutput('logs-stderr-2.log', 'stderr', 50);
}
},
}
}).addBatch({
'When using the logger plugin': {
'with custom log files and the append option set': {
topic: function () {
var monitor = new fmonitor.Monitor(path.join(fixturesDir, 'logs.js'), {
max: 3,
silent: true,
append: true,
outFile: path.join(fixturesDir, 'logs-stdout.log'),
errFile: path.join(fixturesDir, 'logs-stderr.log')
});
monitor.on('exit', this.callback.bind({}, null));
monitor.start();
},
'log files should not be truncated': function (err) {
checkLogOutput('logs-stdout.log', 'stdout', 40);
checkLogOutput('logs-stderr.log', 'stderr', 40);
}
}
}
}).export(module);