-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor of the server-utils lib #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds a new logger package at libs/server-utils with typed log levels, env-driven level resolution, and a pino-based logger; removes the legacy logger under libs/server/utils; updates barrels, TypeScript project references, and workspace/dependency configuration. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App as Application
participant L as logger (pino)
participant GL as getLogLevel()
participant ENV as process.env
participant Z as LogLevelSchema (zod)
participant NE as getNodeEnv()/NodeEnvEnum
App->>L: import logger
activate L
L->>GL: resolve level
activate GL
GL->>ENV: read LOG_LEVEL
GL->>Z: safeParse(value || DEFAULT_LOG_LEVEL)
alt valid
Z-->>GL: LogLevel
GL-->>L: level
else invalid
Z-->>GL: error
GL-->>L: throw Error(cause=zodError)
end
deactivate GL
L->>NE: read NODE_ENV
alt production
L->>L: configure JSON output, omit pid, ISO timestamp
else development
L->>L: configure pino-pretty transport, colorful output
end
L-->>App: ready logger instance
deactivate L
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (13)
libs/server-utils/src/index.ts(1 hunks)libs/server-utils/src/logger/get-log-level.ts(1 hunks)libs/server-utils/src/logger/index.ts(1 hunks)libs/server-utils/src/logger/log-level.ts(1 hunks)libs/server-utils/src/logger/logger.ts(1 hunks)libs/server-utils/tsconfig.json(1 hunks)libs/server-utils/tsconfig.lib.json(2 hunks)libs/server/utils/src/index.ts(0 hunks)libs/server/utils/src/logger/index.ts(0 hunks)libs/server/utils/src/logger/logger.ts(0 hunks)libs/server/utils/src/logger/schema.ts(0 hunks)package.json(2 hunks)tsconfig.json(1 hunks)
💤 Files with no reviewable changes (4)
- libs/server/utils/src/index.ts
- libs/server/utils/src/logger/logger.ts
- libs/server/utils/src/logger/index.ts
- libs/server/utils/src/logger/schema.ts
🧰 Additional context used
🧬 Code graph analysis (3)
libs/server-utils/src/logger/log-level.ts (2)
libs/server-utils/src/index.ts (5)
LOG_LEVELS(5-5)LogLevelSchema(7-7)LogLevelEnum(6-6)LogLevel(2-2)DEFAULT_LOG_LEVEL(4-4)libs/server-utils/src/logger/index.ts (5)
LOG_LEVELS(5-5)LogLevelSchema(7-7)LogLevelEnum(6-6)LogLevel(2-2)DEFAULT_LOG_LEVEL(4-4)
libs/server-utils/src/logger/get-log-level.ts (1)
libs/server-utils/src/logger/log-level.ts (3)
LogLevel(33-33)DEFAULT_LOG_LEVEL(38-38)LogLevelSchema(23-23)
libs/server-utils/src/logger/logger.ts (1)
libs/server-utils/src/logger/get-log-level.ts (1)
getLogLevel(12-22)
🔇 Additional comments (11)
libs/server-utils/tsconfig.lib.json (1)
2-2: LGTM! TypeScript configuration correctly reflects the library relocation.The extends path and project reference adjustments are appropriate for the move from
libs/server/utilstolibs/server-utils, and the core reference supports the@famiglio/coredependency used in the logger implementation.Also applies to: 13-17
package.json (1)
24-24: LGTM! Workspace configuration simplified and dependencies updated.The unified
libs/*workspace glob is cleaner than explicit paths, and the@famiglio/coredevDependency is required for the logger'sgetNodeEnvimport.Also applies to: 58-58
libs/server-utils/tsconfig.json (1)
2-2: LGTM! Project references correctly configured.The configuration changes align with the library relocation and properly reference the core dependency.
Also applies to: 6-8
libs/server-utils/src/logger/get-log-level.ts (1)
12-22: LGTM! Log level resolution is correctly implemented.The function properly validates the environment variable using Zod's
safeParse, provides a sensible default, and includes clear error handling with the validation error as the cause for debugging.libs/server-utils/src/logger/index.ts (1)
1-9: LGTM! Logger module barrel is well-organized.The barrel file cleanly consolidates the logger API surface, following standard TypeScript module patterns.
libs/server-utils/src/logger/logger.ts (1)
34-41: LGTM! Logger configuration is well-structured and environment-aware.The pino configuration appropriately adapts to the runtime environment:
- Development uses
pino-prettyfor human-readable output- Production outputs structured JSON with optimized metadata
The custom timestamp function format (line 38) correctly matches pino's expected format with the leading comma.
libs/server-utils/src/index.ts (1)
1-9: LGTM! Public API surface is clean and comprehensive.The barrel file provides a well-organized entry point for consumers, consolidating all logger-related exports in a single location.
libs/server-utils/src/logger/log-level.ts (4)
6-13: LGTM!The
LOG_LEVELSconstant is well-defined with standard log levels and proper use ofas constfor type narrowing.
28-28: LGTM!The
LogLevelEnumexport provides a clean enum-like interface for accessing log levels.
33-33: LGTM!Using
z.inferto derive the TypeScript type from the Zod schema is the correct approach.
38-38: LGTM!Setting
infoas the default log level is a sensible choice for production environments.
Move lib to
libs/server-utils.Implement
pino-prettytransport.Summary by CodeRabbit
New Features
Refactor
Chores