Skip to content

Commit

Permalink
Log to stderr instead of stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Dec 4, 2024
1 parent 58c220e commit 0c0a8b0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions yarn-project/foundation/src/log/pino-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const { bold, reset } = createColors({ useColor });
const prettyTransport: LoggerOptions['transport'] = {
target: 'pino-pretty',
options: {
destination: 2,
sync: true,
colorize: useColor,
ignore: 'module,pid,hostname,trace_id,span_id,trace_flags',
Expand All @@ -82,10 +83,10 @@ const prettyTransport: LoggerOptions['transport'] = {
},
};

// Transport for vanilla stdout logging as JSON.
const stdoutTransport: LoggerOptions['transport'] = {
// Transport for vanilla stdio logging as JSON.
const stdioTransport: LoggerOptions['transport'] = {
target: 'pino/file',
options: { destination: 1 },
options: { destination: 2 },
};

// Define custom logging levels for pino.
Expand Down Expand Up @@ -117,15 +118,15 @@ const logger = isNode
pinoOpts,
pino.transport({
targets: compactArray([
['1', 'true', 'TRUE'].includes(process.env.LOG_JSON ?? '') ? stdoutTransport : prettyTransport,
['1', 'true', 'TRUE'].includes(process.env.LOG_JSON ?? '') ? stdioTransport : prettyTransport,
process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT ? otelTransport : undefined,
]),
}),
)
: pino({ ...pinoOpts, browser: { asObject: false } });

// Log the logger configuration.
logger.info(
logger.verbose(
{
module: 'logger',
...logFilters.reduce((accum, [module, level]) => ({ ...accum, [`log.${module}`]: level }), {}),
Expand Down

0 comments on commit 0c0a8b0

Please sign in to comment.