forked from stelcheck/node-graylog2
-
Notifications
You must be signed in to change notification settings - Fork 36
/
test.js
85 lines (76 loc) · 3.14 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
var graylog = require('./graylog'),
fs = require('fs'),
assert = require('assert'),
file,
data,
servers = [
{ 'host': '127.0.0.1', 'port': 12201 }
];
var client = new graylog.graylog({
servers: servers,
facility: 'Test logger / Node.JS Test Script'
});
console.log('---------------------------------------------');
console.log('Sending three test as info, warning and error');
console.log('---------------------------------------------');
client.log('test1', 'i get this1', {cool: 'beans'});
client.warn('test2', 'i get this2', {cool: 'beans'});
client.error('test3', 'i get this3', {cool: 'beans'});
client.error('customTime', 'i get this3', {cool: 'beans'}, new Date('2012-10-10 13:20:31.619Z'));
console.log('');
console.log('---------------------------------------------');
console.log('Sending Sean Connery\' picture (as critical)');
console.log('---------------------------------------------');
file = './data/sean.jpg';
data = fs.readFileSync(file);
client.critical('My Nice Sean Connery Picture', data.toString(), {name: 'James Bond'});
console.log('');
console.log('---------------------------------------------');
console.log('Sending data of different sizes (as critical)');
console.log('---------------------------------------------');
for (var i = 4; i <= 128; i *= 2) {
file = './data/' + i + '.dat';
data = fs.readFileSync(file);
console.log('sending', file);
client.critical('Test 4 ' + file, data.toString(), {datafile: i + '.dat'});
}
console.log('');
console.log('---------------------------------------------');
console.log('Sending different parameters');
console.log('---------------------------------------------');
client.log('ParametersTest - Only short message');
client.log('ParametersTest - Short message and json', {cool: 'beans'});
client.log('ParametersTest - Short message and full message', 'Full message');
client.log('ParametersTest - Short Message with full message and json', 'Full message', {cool: 'beans'});
console.log('');
console.log('---------------------------------------------');
console.log('Sending without deflate');
console.log('---------------------------------------------');
client.deflate = 'never';
for (var i = 4; i <= 64; i *= 2) {
file = './data/' + i + '.dat';
data = fs.readFileSync(file);
console.log('sending', file);
client.critical('Test 4 ' + file, data.toString(), {datafile: i + '.dat'});
}
client.deflate = 'optimal';
console.log('');
client.close(function () {
console.log('Insertion complete. Please check', 'http://' + servers[0].host + ':3000', 'and verify that insertion was successfull');
console.log('');
});
console.log('---------------------------------------------');
console.log('Checking deflate assertion');
console.log('---------------------------------------------');
try {
new graylog.graylog({
servers: servers,
facility: 'Test logger / Node.JS Test Script',
deflate: 'not an option'
});
throw new Error('should not get here')
} catch (err) {
assert(
err.message === 'deflate must be one of "optimal", "always", or "never". was "not an option"',
'assertion msg was wrong: ' + err.message);
}