Skip to content

Commit

Permalink
fix: Fix sync log destination and specify out/err destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Mar 1, 2024
1 parent 4062693 commit 341357c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/destinations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pinoRoll from 'pino-roll';
import {LogLevelStreamEntry, LogLevel, LogOptions, StreamDestination, FileDestination} from "./types.js";
import {DestinationStream, pino} from "pino";
import {DestinationStream, pino, destination} from "pino";
import prettyDef, {PrettyOptions} from "pino-pretty";
import {prettyConsole, prettyFile} from "./pretty.js";
import {fileOrDirectoryIsWriteable} from "./util.js";
Expand Down Expand Up @@ -45,7 +45,7 @@ export const buildDestinationFile = (level: LogLevel | false, options: FileDesti

try {
fileOrDirectoryIsWriteable(logPath);
const dest = pino.destination({dest: path, sync: false})
const dest = destination({dest: logPath, mkdir: true, sync: false})

return {
level: level,
Expand All @@ -64,15 +64,16 @@ export const buildDestinationStream = (level: LogLevel, options: StreamDestinati
}

export const buildDestinationStdout = (level: LogLevel, options: Omit<StreamDestination, 'destination'> = {}): LogLevelStreamEntry => {
const opts = {...prettyConsole, ...options, destination: destination({dest: 1, sync: true})}
return {
level: level,
stream: prettyDef.default({...prettyConsole, ...options, destination: 1})
stream: prettyDef.default(opts)
}
}

export const buildDestinationStderr = (level: LogLevel, options: Omit<StreamDestination, 'destination'> = {}): LogLevelStreamEntry => {
return {
level: level,
stream: prettyDef.default({...prettyConsole, ...options, destination: 2})
stream: prettyDef.default({...prettyConsole, ...options, destination: destination({dest: 2, sync: true})})
}
}

0 comments on commit 341357c

Please sign in to comment.