Repository navigation
fix(logger): configure log level and format with env vars - #65
Merged
Merged
Conversation
Add TYPEWRITER_LOG_LEVEL ("trace" | "debug" | "info" | "warn" | "error",
default "info") and TYPEWRITER_LOG_FORMAT ("pretty" | "json", default
"json" when NODE_ENV is "production", else "pretty"). An invalid value
throws when the module loads.
The harness benchmark now runs at "info" and does not mute the console.
Comment on lines
+27
to
+39
| function readEnv<const T extends string>( | ||
| name: string, | ||
| values: readonly T[], | ||
| fallback: T, | ||
| ): T { | ||
| const value = process.env[name]; | ||
| if (value === undefined || value === "") return fallback; | ||
| if (!(values as readonly string[]).includes(value)) { | ||
| throw new Error( | ||
| `${name} must be one of ${values.map((v) => `"${v}"`).join(", ")}, got "${value}"`, | ||
| ); | ||
| } | ||
| return value as T; |
There was a problem hiding this comment.
The new environment settings have no automated tests. A later change could silently hide logs or stop server startup without failing the suite.
Add tests that import logger.ts in a fresh process for each case: unset and empty values, supported levels and formats, production defaults, and invalid values. Fresh processes matter because the module reads these settings only once.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/typewriter/src/logger.ts
Line: 27-39
Comment:
**Logging settings lack tests**
The new environment settings have no automated tests. A later change could silently hide logs or stop server startup without failing the suite.
Add tests that import `logger.ts` in a fresh process for each case: unset and empty values, supported levels and formats, production defaults, and invalid values. Fresh processes matter because the module reads these settings only once.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TYPEWRITER_LOG_LEVEL:"trace" | "debug" | "info" | "warn" | "error". The default is"info".TYPEWRITER_LOG_FORMAT:"pretty" | "json". The default is"json"whenNODE_ENVis"production", else"pretty".createTypewriter()in the READMEs.TYPEWRITER_LOG_LEVEL=infoand does not muteconsole.log/console.debug. All hot-path logs are Debug, so nothing prints atinfo.Behavior changes
DebugtoInfo. SetTYPEWRITER_LOG_LEVEL=debugto see the old logs.Test plan
tsc --noEmitandbun testinpackages/typewriter(79 pass)debug, productionjson, theprettyoverride, and an invalid valuebun run benchmarkpasses the test. The script still exits with code 1 because of ahalt: OutOfGas(MemoryLimit)revert that also occurs onmain.🤖 Generated with Claude Code
The PR appears safe to merge, with a non-blocking request to test the new logging settings.
Fix with agent prompt
Summary
Adds environment settings for log level and format, documents them in both READMEs, and removes console muting from the benchmark.
Reviews (1) · Last reviewed commit: "fix(logger): configure log level and for..." · Reviewed by Greptile