Skip to content

Adds log level option and configuration via environment in scripts.#271

Open
cleitonme wants to merge 1 commit intoasternic:mainfrom
cleitonme:logstype
Open

Adds log level option and configuration via environment in scripts.#271
cleitonme wants to merge 1 commit intoasternic:mainfrom
cleitonme:logstype

Conversation

@cleitonme
Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the application's logging capabilities by introducing flexible log level configuration. Users can now specify the desired logging verbosity through a new command-line flag or an environment variable, allowing for easier debugging and operational control without modifying code. This change improves observability and adaptability of the application in various environments.

Highlights

  • Log Level Configuration: Introduced a new command-line flag, -loglevel, to control the application's logging verbosity, supporting 'debug', 'info', 'warn', and 'error' levels.
  • Environment Variable Support: Enabled configuration of the log level via the LOG_LEVEL environment variable, which takes precedence over the command-line flag for flexible deployment.
  • Dynamic Logging: Integrated zerolog to dynamically set the global logging level based on the provided configuration, with a default to 'info' and a warning for invalid levels.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .env.sample
    • Added LOG_LEVEL environment variable example with supported values (debug, info, warn, error).
  • README.md
    • Updated documentation to include the new -loglevel command-line option and its available values.
  • docker-compose-swarm.yaml
    • Configured the LOG_LEVEL environment variable to info for the main service.
  • docker-compose.yml
    • Configured the LOG_LEVEL environment variable to info for the main service.
  • main.go
    • Implemented a new loglevel command-line flag with a default of 'info'.
    • Added logic to read LOG_LEVEL from environment variables, overriding the flag if set.
    • Integrated zerolog to set the global logging level based on the configured value, handling debug, info, warn, and error levels.
    • Included a fallback to 'info' and a warning message for invalid log level inputs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a configurable log level, which is a great enhancement. The implementation is mostly solid, with a new command-line flag and environment variable to control the log level. I've made a few suggestions to improve consistency and configurability:

  • In main.go, the precedence of the environment variable over the command-line flag is inconsistent with other settings in the application. I've suggested a change to align this.
  • In docker-compose.yml and docker-compose-swarm.yaml, the LOG_LEVEL is hardcoded. I've suggested using variable substitution to allow it to be configured from the environment, which is the pattern used for other variables.

- TZ=${TZ:-America/Sao_Paulo}
- WEBHOOK_FORMAT=${WEBHOOK_FORMAT:-json}
- SESSION_DEVICE_NAME=${SESSION_DEVICE_NAME:-WuzAPI}
- LOG_LEVEL=info
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The LOG_LEVEL is hardcoded. It should use variable substitution to allow configuration from the shell environment, which is the standard practice for swarm deployments as noted in the README. This provides flexibility for different environments.

      - LOG_LEVEL=${LOG_LEVEL:-info}

- TZ=${TZ:-America/Sao_Paulo}
- WEBHOOK_FORMAT=${WEBHOOK_FORMAT:-json}
- SESSION_DEVICE_NAME=${SESSION_DEVICE_NAME:-WuzAPI}
- LOG_LEVEL=info
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The LOG_LEVEL is hardcoded to info. To allow for easier configuration via the .env file, it should use variable substitution with a default value, similar to other environment variables in this file. This improves configurability.

      - LOG_LEVEL=${LOG_LEVEL:-info}

Comment on lines +185 to +187
if v := os.Getenv("LOG_LEVEL"); v != "" {
*logLevel = v
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation for setting the log level from an environment variable gives it higher precedence than the command-line flag. This is inconsistent with how other configurations like WUZAPI_ADDRESS and WUZAPI_PORT are handled in this file, where command-line flags override environment variables. To maintain consistency, the logic should be adjusted to only use the environment variable if the command-line flag has not been set (i.e., it has its default value of "info"). You might also want to update the comment on line 184 to reflect this change, for example: // Configure log level from environment variable if flag is default.

Suggested change
if v := os.Getenv("LOG_LEVEL"); v != "" {
*logLevel = v
}
if v := os.Getenv("LOG_LEVEL"); v != "" && *logLevel == "info" {
*logLevel = v
}

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.

1 participant