@@ -6,98 +6,119 @@ import * as TransportType from "winston-transport";
66const Transport : typeof TransportType = require ( "winston-transport" ) ;
77
88class OutputChannelTransport extends Transport {
9- constructor ( private readonly ouptutChannel : vscode . OutputChannel ) {
10- super ( ) ;
11- }
9+ constructor ( private readonly ouptutChannel : vscode . OutputChannel ) {
10+ super ( ) ;
11+ }
1212
13- public log ( info : any , next : ( ) => void ) : void {
14- this . ouptutChannel . appendLine ( info [ Symbol . for ( ' message' ) ] ) ;
15- next ( ) ;
16- }
13+ public log ( info : any , next : ( ) => void ) : void {
14+ this . ouptutChannel . appendLine ( info [ Symbol . for ( " message" ) ] ) ;
15+ next ( ) ;
16+ }
1717}
1818
1919export type LogFilePathProvider = ( name : string ) => string ;
2020
2121export interface Logger {
22- debug ( message : string , ...args : any [ ] ) : void
23- error ( error : string | Error , ...args : any [ ] ) : void
24- info ( message : string , ...args : any [ ] ) : void
25- warn ( message : string , ...args : any [ ] ) : void
22+ debug ( message : string , ...args : any [ ] ) : void ;
23+ error ( error : string | Error , ...args : any [ ] ) : void ;
24+ info ( message : string , ...args : any [ ] ) : void ;
25+ warn ( message : string , ...args : any [ ] ) : void ;
2626}
2727
2828export class LLDBDAPLogger implements vscode . Disposable {
29- private disposables : vscode . Disposable [ ] = [ ] ;
30- private logger : winston . Logger ;
29+ private disposables : vscode . Disposable [ ] = [ ] ;
30+ private logger : winston . Logger ;
3131
32- constructor ( public readonly logFilePath : string , ouptutChannel : vscode . OutputChannel ) {
33- const ouptutChannelTransport = new OutputChannelTransport ( ouptutChannel ) ;
34- ouptutChannelTransport . level = this . outputChannelLevel ( ) ;
35- this . logger = winston . createLogger ( {
36- transports : [
37- new winston . transports . File ( { filename : logFilePath , level : "debug" } ) , // File logging at the 'debug' level
38- ouptutChannelTransport
39- ] ,
40- format : winston . format . combine (
41- winston . format . errors ( { stack : true } ) ,
42- winston . format . timestamp ( { format : "YYYY-MM-DD HH:mm:ss.SSS" } ) , // This is the format of `vscode.LogOutputChannel`
43- winston . format . printf ( msg => `${ msg . timestamp } [${ msg . level } ] ${ msg . message } ${ msg . stack ? msg . stack : '' } ` ) ,
44- ) ,
45- } ) ;
46- if ( process . env . NODE_ENV !== 'production' ) {
47- this . logger . add ( new winston . transports . Console ( {
48- level : "error"
49- } ) ) ;
50- }
51- this . disposables . push (
52- {
53- dispose : ( ) => this . logger . close ( )
54- } ,
55- vscode . workspace . onDidChangeConfiguration ( e => {
56- if ( e . affectsConfiguration ( "lldb-dap.verboseLogging" ) ) {
57- ouptutChannelTransport . level = this . outputChannelLevel ( ) ;
58- }
59- } )
60- ) ;
32+ constructor (
33+ public readonly logFilePath : string ,
34+ ouptutChannel : vscode . OutputChannel ,
35+ ) {
36+ const ouptutChannelTransport = new OutputChannelTransport ( ouptutChannel ) ;
37+ ouptutChannelTransport . level = this . outputChannelLevel ( ) ;
38+ this . logger = winston . createLogger ( {
39+ transports : [
40+ new winston . transports . File ( { filename : logFilePath , level : "debug" } ) , // File logging at the 'debug' level
41+ ouptutChannelTransport ,
42+ ] ,
43+ format : winston . format . combine (
44+ winston . format . errors ( { stack : true } ) ,
45+ winston . format . timestamp ( { format : "YYYY-MM-DD HH:mm:ss.SSS" } ) , // This is the format of `vscode.LogOutputChannel`
46+ winston . format . printf (
47+ ( msg ) =>
48+ `${ msg . timestamp } [${ msg . level } ] ${ msg . message } ${ msg . stack ? msg . stack : "" } ` ,
49+ ) ,
50+ ) ,
51+ } ) ;
52+ if ( process . env . NODE_ENV !== "production" ) {
53+ this . logger . add (
54+ new winston . transports . Console ( {
55+ level : "error" ,
56+ } ) ,
57+ ) ;
6158 }
59+ this . disposables . push (
60+ {
61+ dispose : ( ) => this . logger . close ( ) ,
62+ } ,
63+ vscode . workspace . onDidChangeConfiguration ( ( e ) => {
64+ if ( e . affectsConfiguration ( "lldb-dap.verboseLogging" ) ) {
65+ ouptutChannelTransport . level = this . outputChannelLevel ( ) ;
66+ }
67+ } ) ,
68+ ) ;
69+ }
6270
63- debug ( message : string , ...args : any [ ] ) {
64- this . logger . debug ( [ message , ...args ] . map ( m => this . normalizeMessage ( m ) ) . join ( " " ) ) ;
65- }
71+ debug ( message : string , ...args : any [ ] ) {
72+ this . logger . debug (
73+ [ message , ...args ] . map ( ( m ) => this . normalizeMessage ( m ) ) . join ( " " ) ,
74+ ) ;
75+ }
6676
67- info ( message : string , ...args : any [ ] ) {
68- this . logger . info ( [ message , ...args ] . map ( m => this . normalizeMessage ( m ) ) . join ( " " ) ) ;
69- }
77+ info ( message : string , ...args : any [ ] ) {
78+ this . logger . info (
79+ [ message , ...args ] . map ( ( m ) => this . normalizeMessage ( m ) ) . join ( " " ) ,
80+ ) ;
81+ }
7082
71- warn ( message : string , ...args : any [ ] ) {
72- this . logger . warn ( [ message , ...args ] . map ( m => this . normalizeMessage ( m ) ) . join ( " " ) ) ;
73- }
83+ warn ( message : string , ...args : any [ ] ) {
84+ this . logger . warn (
85+ [ message , ...args ] . map ( ( m ) => this . normalizeMessage ( m ) ) . join ( " " ) ,
86+ ) ;
87+ }
7488
75- error ( message : Error | string , ...args : any [ ] ) {
76- if ( message instanceof Error ) {
77- this . logger . error ( message ) ;
78- this . logger . error ( [ ... args ] . map ( m => this . normalizeMessage ( m ) ) . join ( " " ) ) ;
79- return ;
80- }
81- this . logger . error ( [ message , ... args ] . map ( m => this . normalizeMessage ( m ) ) . join ( " " ) ) ;
89+ error ( message : Error | string , ...args : any [ ] ) {
90+ if ( message instanceof Error ) {
91+ this . logger . error ( message ) ;
92+ this . logger . error (
93+ [ ... args ] . map ( ( m ) => this . normalizeMessage ( m ) ) . join ( " " ) ,
94+ ) ;
95+ return ;
8296 }
97+ this . logger . error (
98+ [ message , ...args ] . map ( ( m ) => this . normalizeMessage ( m ) ) . join ( " " ) ,
99+ ) ;
100+ }
83101
84- private normalizeMessage ( message : any ) {
85- if ( typeof message === "string" ) {
86- return message ;
87- }
88- try {
89- return JSON . stringify ( message ) ;
90- } catch ( e ) {
91- return `${ message } ` ;
92- }
102+ private normalizeMessage ( message : any ) {
103+ if ( typeof message === "string" ) {
104+ return message ;
93105 }
94-
95- private outputChannelLevel ( ) : string {
96- return vscode . workspace . getConfiguration ( "lldb-dap" ) . get ( "verboseLogging" , false ) ?
97- "debug" : "info" ;
106+ try {
107+ return JSON . stringify ( message ) ;
108+ } catch ( e ) {
109+ return ` ${ message } ` ;
98110 }
111+ }
99112
100- dispose ( ) {
101- this . disposables . forEach ( d => d . dispose ( ) ) ;
102- }
103- }
113+ private outputChannelLevel ( ) : string {
114+ return vscode . workspace
115+ . getConfiguration ( "lldb-dap" )
116+ . get ( "verboseLogging" , false )
117+ ? "debug"
118+ : "info" ;
119+ }
120+
121+ dispose ( ) {
122+ this . disposables . forEach ( ( d ) => d . dispose ( ) ) ;
123+ }
124+ }
0 commit comments