@@ -15,6 +15,8 @@ import { inspect } from "util";
1515
1616@injectable ( )
1717export class PinoLogger implements Contracts . Kernel . Logger {
18+ static LOG_LEVELS = new Set ( [ "emergency" , "alert" , "critical" , "error" , "warning" , "notice" , "info" , "debug" ] ) ;
19+
1820 @inject ( Identifiers . Application . Instance )
1921 private readonly app ! : Contracts . Kernel . Application ;
2022
@@ -39,6 +41,22 @@ export class PinoLogger implements Contracts.Kernel.Logger {
3941
4042 public async make ( options ?: any ) : Promise < Contracts . Kernel . Logger > {
4143 this . #stream = new PassThrough ( ) ;
44+
45+ if ( options . workerMode ) {
46+ this . #logger = Object . fromEntries (
47+ [ ...PinoLogger . LOG_LEVELS ] . map ( ( level ) => [
48+ level ,
49+ ( message : string ) => {
50+ process . stdout . write ( `[${ level } ] (${ this . app . thread ( ) } ) ${ message } \n` ) ;
51+ } ,
52+ ] ) ,
53+ ) as unknown as pino . Logger <
54+ "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning"
55+ > ;
56+
57+ return this ;
58+ }
59+
4260 this . #logger = pino . default (
4361 {
4462 base : null ,
@@ -64,7 +82,7 @@ export class PinoLogger implements Contracts.Kernel.Logger {
6482 this . #stream,
6583 ) ;
6684
67- if ( this . # isValidLevel( options . levels . console ) ) {
85+ if ( this . isValidLevel ( options . levels . console ) ) {
6886 pump (
6987 this . #stream,
7088 split ( ) ,
@@ -77,7 +95,7 @@ export class PinoLogger implements Contracts.Kernel.Logger {
7795 ) ;
7896 }
7997
80- if ( this . # isValidLevel( options . levels . file ) ) {
98+ if ( this . isValidLevel ( options . levels . file ) ) {
8199 this . #combinedFileStream = new pumpify (
82100 split ( ) ,
83101 this . #createPrettyTransport( options . levels . file , { colorize : false } ) ,
@@ -164,14 +182,8 @@ export class PinoLogger implements Contracts.Kernel.Logger {
164182 }
165183
166184 #createPrettyTransport( level : string , prettyOptions ?: PrettyOptions ) : Transform {
167- const thread = this . app . thread ( ) ;
168- const ignore = this . app . isWorker ( ) ? `` : `pid` ;
169-
170185 const pinoPretty = prettyFactory ( {
171- customPrettifiers : {
172- pid : ( ) => thread ,
173- } ,
174- ignore,
186+ ignore : "pid" ,
175187 levelFirst : false ,
176188 translateTime : "yyyy-mm-dd HH:MM:ss.l" ,
177189 ...prettyOptions ,
@@ -229,7 +241,7 @@ export class PinoLogger implements Contracts.Kernel.Logger {
229241 ) ;
230242 }
231243
232- # isValidLevel( level : string ) : boolean {
233- return [ "emergency" , "alert" , "critical" , "error" , "warning" , "notice" , "info" , "debug" ] . includes ( level ) ;
244+ public isValidLevel ( level : string ) : boolean {
245+ return PinoLogger . LOG_LEVELS . has ( level ) ;
234246 }
235247}
0 commit comments