Skip to content

Conversation

@dcdavidev
Copy link
Contributor

@dcdavidev dcdavidev commented Oct 11, 2025

Move lib to libs/server-utils.
Implement pino-pretty transport.

Summary by CodeRabbit

  • New Features

    • Centralized logging utilities available from a single import.
    • Environment-driven log level with validation and a sensible default.
    • Human-friendly pretty logs in development; compact JSON logs in production.
  • Refactor

    • Logging implementation moved and public API streamlined.
  • Chores

    • Updated workspace and TypeScript project references to reflect the new library layout.

@coderabbitai
Copy link

coderabbitai bot commented Oct 11, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
New server-utils logger
libs/server-utils/src/logger/log-level.ts, libs/server-utils/src/logger/get-log-level.ts, libs/server-utils/src/logger/logger.ts, libs/server-utils/src/logger/index.ts, libs/server-utils/src/index.ts
Added log level constants/schema/types, getLogLevel() (env-validated), configured pino logger (dev vs prod), and consolidated re-exports in package barrel.
Remove legacy server/utils logger
libs/server/utils/src/logger/logger.ts, libs/server/utils/src/logger/schema.ts, libs/server/utils/src/logger/index.ts, libs/server/utils/src/index.ts
Deleted previous logger implementation, schema, and related re-exports from the old package path.
TS config / project refs
libs/server-utils/tsconfig.json, libs/server-utils/tsconfig.lib.json, tsconfig.json
Updated extends paths and added/adjusted project references to point to ../core and renamed root reference from ./libs/server/utils to ./libs/server-utils.
Workspace & deps
package.json
Broadened workspace globs to libs/* and added @famiglio/core as a devDependency.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit nudges logs at dawn,
New burrow formed where old is gone.
Levels checked and envs in tune,
Pretty in dev, production immune.
Thump—pino hums beneath the moon. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description does not follow the repository’s template and is missing required sections such as a detailed “Description,” “Related Issues,” “Checklist,” and “Additional Notes.” It only provides two brief statements, leaving out critical context on the problem addressed, any linked issues, verification steps, or documentation updates. This makes it difficult to assess completeness and adherence to project guidelines. Please revise the description using the provided template by adding a comprehensive “Description” section explaining the purpose and changes, referencing any related issues to close, completing the checklist for style and testing, and including any additional notes or screenshots as needed.
Title Check ❓ Inconclusive The title “Refactor of the server-utils lib” is related to the changeset but is overly generic and does not highlight the primary modifications such as relocating the library to libs/server-utils or integrating the pino-pretty transport. It fails to summarize the most significant updates made in this PR, which may reduce clarity for reviewers skimming the commit history. A more descriptive title would better convey the core intent of the refactor. Consider updating the title to explicitly mention key changes like moving the library path to libs/server-utils and adding the pino-pretty transport for logging, which will improve clarity and context for anyone reviewing the PR.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/server-utils-lib

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14cbbfb and ac4103b.

📒 Files selected for processing (1)
  • libs/server-utils/src/logger/log-level.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/server-utils/src/logger/log-level.ts

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 751952a and 14cbbfb.

⛔ Files ignored due to path filters (1)
  • package-lock.json is 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/utils to libs/server-utils, and the core reference supports the @famiglio/core dependency 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/core devDependency is required for the logger's getNodeEnv import.

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-pretty for 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_LEVELS constant is well-defined with standard log levels and proper use of as const for type narrowing.


28-28: LGTM!

The LogLevelEnum export provides a clean enum-like interface for accessing log levels.


33-33: LGTM!

Using z.infer to derive the TypeScript type from the Zod schema is the correct approach.


38-38: LGTM!

Setting info as the default log level is a sensible choice for production environments.

@dcdavidev dcdavidev merged commit d3d2642 into main Oct 12, 2025
5 checks passed
@dcdavidev dcdavidev deleted the refactor/server-utils-lib branch October 12, 2025 07:49
@coderabbitai coderabbitai bot mentioned this pull request Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants