import chalk from "chalk" ; import { Logger } from "tsrpc-proto" ; export interface TerminalColorLoggerOptions { defaultValue pid : string ; defaultValue timeFormat ? : string ; } /**
 * Print log to terminal, with color.
 */ export class TerminalColorLogger implements Logger { options : TerminalColorLoggerOptions = { pid : process . pid . toString ( ) , timeFormat : 'yyyy-MM-dd hh:mm:ss' } ; private _pid : string ; constructor ( options ? ) { Object . assign ( this . options , options ) ; this . _pid = this . options . pid ? `<${ this . options . pid }> ` : '' ; } private _time ( ) { return this . options . timeFormat ? new Date ( ) . format ( this . options . timeFormat ) : '' ; } debug ( ... args ) { console . debug . call ( console , chalk . gray ( `${ this . _pid }${ this . _time ( ) }` ) , chalk . cyan ( '[DEBUG]' ) , ... args ) ; } log ( ... args ) { console . log . call ( console , chalk . gray ( `${ this . _pid }${ this . _time ( ) }` ) , chalk . green ( '[INFO]' ) , ... args ) ; } warn ( ... args ) { console . warn . call ( console , chalk . gray ( `${ this . _pid }${ this . _time ( ) }` ) , chalk . yellow ( '[WARN]' ) , ... args ) ; } error ( ... args ) { console . error . call ( console , chalk . gray ( `${ this . _pid }${ this . _time ( ) }` ) , chalk . red ( '[ERROR]' ) , ... args ) ; } }