Skip to content

Commit 19e8dac

Browse files
committed
feat(logger): add pretty printing to logs if POWERTOOLS_DEV env var set to truthy value
1 parent cb2dc62 commit 19e8dac

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/logger/src/Logger.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { LogItem } from './log';
66
import cloneDeep from 'lodash.clonedeep';
77
import merge from 'lodash.merge';
88
import { ConfigServiceInterface, EnvironmentVariablesService } from './config';
9+
import { LogJsonIndent } from './types';
910
import type {
1011
ClassThatLogs,
1112
Environment,
@@ -569,7 +570,10 @@ class Logger extends Utility implements ClassThatLogs {
569570

570571
const consoleMethod = logLevel.toLowerCase() as keyof ClassThatLogs;
571572

572-
this.console[consoleMethod](JSON.stringify(log.getAttributes(), this.removeCircularDependencies()));
573+
const isDevMode = this.getEnvVarsService().getDevMode();
574+
const INDENTATION: LogJsonIndent = isDevMode ? LogJsonIndent.PRETTY : LogJsonIndent.COMPACT;
575+
576+
this.console[consoleMethod](JSON.stringify(log.getAttributes(), this.removeCircularDependencies(), INDENTATION));
573577
}
574578

575579
/**

packages/logger/src/types/Logger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ export {
7474
ConstructorOptions,
7575
HandlerOptions
7676
};
77+
78+
export const enum LogJsonIndent {
79+
PRETTY = 4,
80+
COMPACT = 0,
81+
}

0 commit comments

Comments
 (0)