File tree 3 files changed +18
-10
lines changed
3 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 1
1
import { EventEmitter } from 'events' ;
2
2
3
3
import { Transport } from '../utils/transport' ;
4
- import { logger as loggerModule } from '../utils/logger' ;
4
+ import { Logger } from '../utils/logger' ;
5
5
import { VimValue } from '../types/VimValue' ;
6
6
7
7
export interface BaseConstructorOptions {
8
8
transport ?: Transport ;
9
- logger ?: typeof loggerModule ;
9
+ logger ?: Logger ;
10
10
data ?: Buffer ;
11
11
metadata ?: any ;
12
12
client ?: any ;
@@ -31,7 +31,7 @@ export class BaseApi extends EventEmitter {
31
31
32
32
protected prefix : string ;
33
33
34
- public logger : typeof loggerModule ;
34
+ public logger : Logger ;
35
35
36
36
public data : Buffer | number ;
37
37
@@ -49,7 +49,8 @@ export class BaseApi extends EventEmitter {
49
49
50
50
this . setTransport ( transport ) ;
51
51
this . data = data ;
52
- this . logger = logger || loggerModule ;
52
+ // eslint-disable-next-line global-require
53
+ this . logger = logger || require ( '../utils/logger' ) . logger ;
53
54
this . client = client ;
54
55
55
56
if ( metadata ) {
Original file line number Diff line number Diff line change @@ -2,20 +2,24 @@ import { createConnection } from 'net';
2
2
import * as child from 'child_process' ;
3
3
4
4
import { NeovimClient } from '../api/client' ;
5
- import { logger } from '../utils/logger' ;
5
+ import { Logger } from '../utils/logger' ;
6
6
7
7
export interface Attach {
8
8
reader ?: NodeJS . ReadableStream ;
9
9
writer ?: NodeJS . WritableStream ;
10
10
proc ?: NodeJS . Process | child . ChildProcess ;
11
11
socket ?: string ;
12
+ options ?: {
13
+ logger ?: Logger ;
14
+ } ;
12
15
}
13
16
14
17
export function attach ( {
15
18
reader : _reader ,
16
19
writer : _writer ,
17
20
proc,
18
21
socket,
22
+ options = { } ,
19
23
} : Attach ) {
20
24
let writer ;
21
25
let reader ;
@@ -33,7 +37,9 @@ export function attach({
33
37
}
34
38
35
39
if ( writer && reader ) {
36
- const neovim = new NeovimClient ( { logger } ) ;
40
+ // eslint-disable-next-line global-require
41
+ const loggerInstance = options . logger || require ( '../utils/logger' ) . logger ; // lazy load to winston only if needed
42
+ const neovim = new NeovimClient ( { logger : loggerInstance } ) ;
37
43
neovim . attach ( {
38
44
writer,
39
45
reader,
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ import * as winston from 'winston';
2
2
3
3
const level = process . env . NVIM_NODE_LOG_LEVEL || 'debug' ;
4
4
5
- const logger = winston . createLogger ( {
5
+ const winstonLogger = winston . createLogger ( {
6
6
level,
7
7
} ) ;
8
8
9
9
if ( process . env . NVIM_NODE_LOG_FILE ) {
10
- logger . add (
10
+ winstonLogger . add (
11
11
new winston . transports . File ( {
12
12
filename : process . env . NVIM_NODE_LOG_FILE ,
13
13
level,
@@ -16,11 +16,12 @@ if (process.env.NVIM_NODE_LOG_FILE) {
16
16
}
17
17
18
18
if ( process . env . ALLOW_CONSOLE ) {
19
- logger . add (
19
+ winstonLogger . add (
20
20
new winston . transports . Console ( {
21
21
format : winston . format . simple ( ) ,
22
22
} )
23
23
) ;
24
24
}
25
25
26
- export { logger } ;
26
+ export type Logger = Pick < winston . Logger , 'info' | 'warn' | 'error' | 'debug' > ;
27
+ export const logger : Logger = winstonLogger ;
You can’t perform that action at this time.
0 commit comments