Skip to content

Commit 60b2449

Browse files
committed
fix: pino pretty breaking in cli
1 parent 75ada93 commit 60b2449

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/shared/logger/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import { createRequire } from "module";
2+
13
import pino from "pino";
24

5+
function hasPinoPretty(): boolean {
6+
try {
7+
const require = createRequire(import.meta.url);
8+
require.resolve("pino-pretty");
9+
return true;
10+
} catch {
11+
return false;
12+
}
13+
}
14+
315
/**
416
* Minimal logger interface used throughout the library.
517
* Matches the subset of pino's API that is actually called internally,
@@ -43,11 +55,12 @@ export const silentLogger: ILogger = {
4355

4456
function createDefaultLogger(): ILogger {
4557
const isDev = process.env["NODE_ENV"] !== "production";
58+
const usePretty = isDev && hasPinoPretty();
4659

4760
return pino({
4861
name: "test-smell-watcher",
4962
level: process.env["LOG_LEVEL"] ?? "info",
50-
transport: isDev
63+
transport: usePretty
5164
? {
5265
target: "pino-pretty",
5366
options: {

0 commit comments

Comments
 (0)