This repository was archived by the owner on Aug 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·68 lines (59 loc) · 2.22 KB
/
cli.js
File metadata and controls
executable file
·68 lines (59 loc) · 2.22 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
#!/usr/bin/env node
const program = require('commander');
const split2 = require('split2');
const pkg = require('./package.json');
const SeqStream = require('./seq_stream');
const StringStream = require('./seq_string_transform');
function main() {
program
.version(pkg.version)
.option('-s, --serverUrl <serverUrl>', 'Seq server instance')
.option('-k, --apiKey <apiKey>', 'Seq API key')
.option(
'-o, --logOtherAs <Verbose|Debug|Information|Warning|Error|Fatal>',
'Log other output (not formatted through bunyan) to seq at this loglevel. Useful to capture messages if the node process crashes or smilar.',
(string) => {
if (['Verbose', 'Debug', 'Information', 'Warning', 'Error', 'Fatal'].includes(string)) {
return string;
}
console.error(`Warning, skipping option "logOtherAs": Invalid value supplied: "${string}"`);
return undefined;
}
)
.option(
'-p, --property <property>',
'Properties to add to all logs',
(value, previous) => {
const valueSplit = value.split('=');
if (valueSplit.length !== 2) {
console.error(`Warning, skipping option "property": Invalid value specified: "${value}`);
return previous;
}
const current = {
[valueSplit[0]]: valueSplit[1]
};
return Object.assign(previous, current);
},
{}
)
.action(({ serverUrl, apiKey, logOtherAs, property }) => {
try {
const seqStream = new SeqStream({ serverUrl, apiKey, additionalProperties: property });
process.stdin.pipe(split2()).pipe(new StringStream({ logOtherAs })).pipe(seqStream).on('error', console.error);
const handler = (err, name) => {
seqStream.end(() => {
process.exit(0);
});
};
process.on('SIGINT', () => handler(null, 'SIGINT'));
process.on('SIGQUIT', () => handler(null, 'SIGQUIT'));
process.on('SIGTERM', () => handler(null, 'SIGTERM'));
process.on('SIGLOST', () => handler(null, 'SIGLOST'));
process.on('SIGABRT', () => handler(null, 'SIGABRT'));
} catch (error) {
console.error(error);
}
});
program.parse(process.argv);
}
main();