@@ -7,6 +7,10 @@ import { Disposable } from './lifecycle';
77
88export const PR_TREE = 'PullRequestTree' ;
99
10+ interface Stringish {
11+ toString : ( ) => string ;
12+ }
13+
1014class Log extends Disposable {
1115 private readonly _outputChannel : vscode . LogOutputChannel ;
1216 private readonly _activePerfMarkers : Map < string , number > = new Map ( ) ;
@@ -28,36 +32,40 @@ class Log extends Disposable {
2832 this . _activePerfMarkers . delete ( marker ) ;
2933 }
3034
31- private logString ( message : any , component ?: string ) : string {
35+ private logString ( message : string | Error | Stringish | Object , component ?: string ) : string {
36+ let logMessage : string ;
3237 if ( typeof message !== 'string' ) {
38+ const asString = message as Partial < Stringish > ;
3339 if ( message instanceof Error ) {
34- message = message . message ;
35- } else if ( ' toString' in message ) {
36- message = message . toString ( ) ;
40+ logMessage = message . message ;
41+ } else if ( asString . toString ) {
42+ logMessage = asString . toString ( ) ;
3743 } else {
38- message = JSON . stringify ( message ) ;
44+ logMessage = JSON . stringify ( message ) ;
3945 }
46+ } else {
47+ logMessage = message ;
4048 }
41- return component ? `[${ component } ] ${ message } ` : message ;
49+ return component ? `[${ component } ] ${ logMessage } ` : logMessage ;
4250 }
4351
44- public trace ( message : any , component : string ) {
52+ public trace ( message : string | Error | Stringish | Object , component : string ) {
4553 this . _outputChannel . trace ( this . logString ( message , component ) ) ;
4654 }
4755
48- public debug ( message : any , component : string ) {
56+ public debug ( message : string | Error | Stringish | Object , component : string ) {
4957 this . _outputChannel . debug ( this . logString ( message , component ) ) ;
5058 }
5159
52- public appendLine ( message : any , component : string ) {
60+ public appendLine ( message : string | Error | Stringish | Object , component : string ) {
5361 this . _outputChannel . info ( this . logString ( message , component ) ) ;
5462 }
5563
56- public warn ( message : any , component ?: string ) {
64+ public warn ( message : string | Error | Stringish | Object , component ?: string ) {
5765 this . _outputChannel . warn ( this . logString ( message , component ) ) ;
5866 }
5967
60- public error ( message : any , component : string ) {
68+ public error ( message : string | Error | Stringish | Object , component : string ) {
6169 this . _outputChannel . error ( this . logString ( message , component ) ) ;
6270 }
6371}
0 commit comments