Skip to content

fix(logging): Update kafka client logging to use pino logger, set log level from environment variable #46

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

Merged
merged 3 commits into from
May 27, 2025

Conversation

eddyv
Copy link
Member

@eddyv eddyv commented May 27, 2025

This pull request introduces several updates to improve logging functionality, enhance Kafka client configuration, and increment the package version. The changes primarily focus on adding dynamic log level configuration, refining Kafka client initialization, and updating dependencies.

Logging Enhancements:

  • src/env-schema.ts: Added a new environment variable LOG_LEVEL to configure application logging levels dynamically. The default is set to "info."
  • src/logger.ts: Introduced a setLogLevel function to update the logger's level dynamically based on the environment configuration.
  • src/index.ts: Integrated the setLogLevel function to set the logging level during application initialization using the LOG_LEVEL environment variable. [1] [2]

Kafka Client Configuration:

Miscellaneous:

  • package.json: Incremented the package version from 1.0.2 to 1.0.3.

eddyv added 2 commits May 27, 2025 14:28
…r level during initialization

- Added LOG_LEVEL to the environment schema for configurable logging levels (trace, debug, info, warn, error, fatal).
- Implemented setLogLevel function in logger module to update the loggers level based on the environment variable.
- Updated main function to set the logger level after environment initialization, enhancing logging flexibility.
@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 19:00
@eddyv eddyv requested a review from a team as a code owner May 27, 2025 19:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances logging functionality and refines Kafka client configuration by dynamically setting log levels and adjusting client initialization. Key changes include:

  • Introducing a dynamic log level configuration via the new LOG_LEVEL environment variable and the setLogLevel function.
  • Updating the Kafka client initialization to include a custom kafkaLogger and resolving TypeScript type-checking issues.
  • Bumping the package version from 1.0.2 to 1.0.3.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/logger.ts Added setLogLevel function to update logger level dynamically.
src/index.ts Set logging level during initialization using the environment variable.
src/env-schema.ts Introduced LOG_LEVEL configuration in the environment schema.
src/confluent/client-manager.ts Updated Kafka client initialization to include kafkaLogger with explicit type cast.
package.json Incremented package version.

…nction

- Improved LOG_LEVEL environment variable processing to ensure case-insensitivity by using a preprocess step.
- Updated setLogLevel function to accept a LogLevel type, enhancing type safety and clarity in logging level management.
@eddyv eddyv requested a review from Copilot May 27, 2025 19:21
Copy link
Contributor

@stephenheg stephenheg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances application logging by adding dynamic log level configuration, integrates a custom Pino-based logger into the Kafka client, and bumps the package version.

  • Introduce LOG_LEVEL environment variable and Zod schema support
  • Add setLogLevel function and invoke it during startup
  • Wire kafkaLogger into KafkaJS.Kafka initialization, with TS type adjustments
  • Bump version from 1.0.2 to 1.0.3

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/env-schema.ts Added LOG_LEVEL to environment schema
src/logger.ts Introduced setLogLevel function
src/index.ts Set log level from env.LOG_LEVEL on startup
src/confluent/client-manager.ts Configured KafkaJS.Kafka to use kafkaLogger
package.json Updated version to 1.0.3
Comments suppressed due to low confidence (1)

src/confluent/client-manager.ts:122

  • Add unit or integration tests to verify that the custom kafkaLogger is invoked correctly during Kafka client operations to ensure logging integration works as expected.
        new KafkaJS.Kafka({

Comment on lines +19 to +24
z.enum(
Object.keys(logLevels) as [
keyof typeof logLevels,
...Array<keyof typeof logLevels>,
],
),
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using z.nativeEnum(logLevels) instead of manually constructing z.enum(Object.keys(logLevels)) to leverage Zod's native enum support and simplify the schema.

Suggested change
z.enum(
Object.keys(logLevels) as [
keyof typeof logLevels,
...Array<keyof typeof logLevels>,
],
),
z.nativeEnum(logLevels),

Copilot uses AI. Check for mistakes.

@eddyv eddyv merged commit d8a5503 into main May 27, 2025
1 of 2 checks passed
@eddyv eddyv deleted the fix/logging branch May 27, 2025 19:25
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