Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
var assert = require('assert'),
2
fs = require('fs'),
3
path = require('path'),
4
vows = require('vows'),
5
fmonitor = require('../../lib');
6
7
var fixturesDir = path.join(__dirname, '..', 'fixtures');
8
9
function checkLogOutput(file, stream, expectedLength) {
10
var output = fs.readFileSync(path.join(fixturesDir, file), 'utf8'),
11
lines = output.split('\n').slice(0, -1);
12
13
assert.equal(lines.length, expectedLength);
14
lines.forEach(function (line, i) {
15
assert.equal(lines[i], stream + ' ' + (i % 10));
16
});
17
}
18
19
vows.describe('forever-monitor/plugins/logger').addBatch({
20
'When using the logger plugin': {
21
'with custom log files': {
22
topic: function () {
23
var outlogs, errlogs, monitor;
24
25
monitor = new fmonitor.Monitor(path.join(fixturesDir, 'logs.js'), {
26
max: 1,
27
silent: true,
28
outFile: path.join(fixturesDir, 'logs-stdout.log'),
29
errFile: path.join(fixturesDir, 'logs-stderr.log')
30
});
31
32
monitor.on('exit', this.callback.bind({}, null));
33
monitor.start();
34
},
35
'log files should contain correct output': function (err) {
36
checkLogOutput('logs-stdout.log', 'stdout', 10);
37
checkLogOutput('logs-stderr.log', 'stderr', 10);
38
}
39
},
40
'with custom log files and a process that exits': {
41
topic: function () {
42
var monitor = new fmonitor.Monitor(path.join(fixturesDir, 'logs.js'), {
43
max: 5,
44
silent: true,
45
outFile: path.join(fixturesDir, 'logs-stdout-2.log'),
46
errFile: path.join(fixturesDir, 'logs-stderr-2.log')
47
});
48
49
monitor.on('exit', this.callback.bind({}, null));
50
monitor.start();
51
},
52
'logging should continue through process restarts': function (err) {
53
checkLogOutput('logs-stdout-2.log', 'stdout', 50);
54
checkLogOutput('logs-stderr-2.log', 'stderr', 50);
55
}
56
},
57
}
58
}).addBatch({
59
'When using the logger plugin': {
60
'with custom log files and the append option set': {
61
topic: function () {
62
var monitor = new fmonitor.Monitor(path.join(fixturesDir, 'logs.js'), {
63
max: 3,
64
silent: true,
65
append: true,
66
outFile: path.join(fixturesDir, 'logs-stdout.log'),
67
errFile: path.join(fixturesDir, 'logs-stderr.log')
68
});
69
70
monitor.on('exit', this.callback.bind({}, null));
71
monitor.start();
72
},
73
'log files should not be truncated': function (err) {
74
checkLogOutput('logs-stdout.log', 'stdout', 40);
75
checkLogOutput('logs-stderr.log', 'stderr', 40);
76
}
77
}
78
}
79
}).export(module);
80
81
82