1 | import * as riverpig from 'riverpig'
|
2 | import * as debug from 'debug'
|
3 |
|
4 | import through2 = require('through2')
|
5 | const logStream = through2()
|
6 | logStream.pipe(process.stdout)
|
7 |
|
8 | export class ConnectorLogger {
|
9 | river: any
|
10 | tracer: any
|
11 |
|
12 | constructor (namespace: string, config0?: riverpig.LoggerConfig) {
|
13 | this.river = riverpig(namespace, config0)
|
14 | this.tracer = this.river.trace || debug(namespace + ':trace')
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 | info (msg: any, ...elements: any[]): void {
|
20 | this.river.info(msg, ...elements)
|
21 | }
|
22 |
|
23 | warn (msg: any, ...elements: any[]): void {
|
24 | this.river.warn(msg, ...elements)
|
25 | }
|
26 |
|
27 | error (msg: any, ...elements: any[]): void {
|
28 | this.river.error(msg, ...elements)
|
29 | }
|
30 |
|
31 | debug (msg: any, ...elements: any[]): void {
|
32 | this.river.debug(msg, ...elements)
|
33 | }
|
34 |
|
35 | trace (msg: any, ...elements: any[]): void {
|
36 | this.tracer(msg, ...elements)
|
37 | }
|
38 | }
|
39 |
|
40 | export const createRaw = (namespace: string): ConnectorLogger => {
|
41 | return new ConnectorLogger(namespace, {
|
42 | stream: logStream
|
43 | })
|
44 | }
|
45 |
|
46 | export const create = (namespace: string) => createRaw('connector:' + namespace)
|
47 |
|
48 | let outputStream = process.stdout
|
49 | export const setOutputStream = (newOutputStream: NodeJS.WriteStream) => {
|
50 | logStream.unpipe(outputStream)
|
51 | logStream.pipe(newOutputStream)
|
52 | outputStream = newOutputStream
|
53 | }
|