forked from datalust/bunyan-seq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request datalust#17 from stefan-jonasson/master
Support for out-of-process logging
- Loading branch information
Showing
10 changed files
with
1,425 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"tabWidth": 2, | ||
"singleQuote": true, | ||
"useTabs": false, | ||
"trailingComma": "none", | ||
"printWidth": 160 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/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; | ||
} | ||
) | ||
.action(({ serverUrl, apiKey, logOtherAs }) => { | ||
try { | ||
const seqStream = new SeqStream({ serverUrl, apiKey }); | ||
|
||
process.stdin.pipe(split2()).pipe(new StringStream({ logOtherAs })).pipe(seqStream); | ||
|
||
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Writable } from 'stream'; | ||
|
||
declare namespace BunyanSeq { | ||
interface SeqConfig { | ||
serverUrl?: string; | ||
apiKey?: string; | ||
maxBatchingTime?: number; | ||
eventSizeLimit?: number; | ||
batchSizeLimit?: number; | ||
name?: string; | ||
level: config.level; | ||
reemitErrorEvents?: boolean; | ||
onError?: (e: Error) => void; | ||
} | ||
|
||
interface SeqStreamConfig { | ||
name?: string; | ||
level?: string; | ||
type: 'raw'; | ||
stream: Writable; | ||
reemitErrorEvents?: boolean; | ||
} | ||
|
||
function createStream(config: BunyanSeq.SeqConfig): SeqStreamConfig; | ||
} | ||
|
||
export = BunyanSeq; |
Oops, something went wrong.