diff --git a/.changeset/wise-mugs-mix.md b/.changeset/wise-mugs-mix.md new file mode 100644 index 0000000..0a131ef --- /dev/null +++ b/.changeset/wise-mugs-mix.md @@ -0,0 +1,5 @@ +--- +"effect-log": patch +--- + +Visualise empty string, null and undefined messages in PrettyLogger. diff --git a/examples/example-logging-effect.ts b/examples/example-logging-effect.ts index db4e989..71470b1 100644 --- a/examples/example-logging-effect.ts +++ b/examples/example-logging-effect.ts @@ -25,6 +25,15 @@ export const exampleEffect = pipe( Effect.tap(() => Effect.logDebug("Sooo sad, not annotations for me")), Effect.tap(() => Effect.logTrace("Never Gonna Give You Up")), Effect.provide(Logger.minimumLogLevel(LogLevel.All)), - Effect.flatMap(() => Effect.dieMessage("Aaaand it's gone")), Effect.tapErrorCause(Effect.logError), + Effect.flatMap(() => + pipe(Effect.log(""), Effect.annotateLogs("likes", "fp-ts")), + ), + Effect.flatMap(() => + pipe(Effect.log(undefined), Effect.annotateLogs("likes", "fp-ts")), + ), + Effect.flatMap(() => + pipe(Effect.log(null), Effect.annotateLogs("likes", "fp-ts")), + ), + Effect.flatMap(() => Effect.dieMessage("Aaaand it's gone")), ); diff --git a/src/PrettyLogger.ts b/src/PrettyLogger.ts index a8749d5..857bdf2 100644 --- a/src/PrettyLogger.ts +++ b/src/PrettyLogger.ts @@ -59,9 +59,20 @@ const createLogLevelString = (logLevel: LogLevel.LogLevel) => { return `${logLevelColor}${logLevelText}${RESET}`; }; +const messageText = (message: unknown) => { + if (message === undefined) { + return `${DIM}undefined${RESET}`; + } else if (message === null) { + return `${DIM}null${RESET}`; + } else if (message === "") { + return `${DIM}${RESET}`; + } + return serializeUnknown(message); +}; + const createText = (message: unknown, cause: Cause.Cause) => pipe( - [createCauseMessage(cause), serializeUnknown(message)], + [createCauseMessage(cause), messageText(message)], ReadonlyArray.filter((i) => i !== ""), ReadonlyArray.join(" "), );