Skip to content

Add configurable logging level via --log-level option and GRAFITO_LOG_LEVEL environment variable#7

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-15d17040-23a5-45cb-837d-c5ae523723fa
Closed

Add configurable logging level via --log-level option and GRAFITO_LOG_LEVEL environment variable#7
Copilot wants to merge 3 commits intomainfrom
copilot/fix-15d17040-23a5-45cb-837d-c5ae523723fa

Conversation

Copy link
Copy Markdown

Copilot AI commented Sep 19, 2025

This PR implements configurable logging levels as requested in the issue. Previously, Grafito was hardcoded to use DEBUG logging level, which could be too verbose for production use or insufficient for troubleshooting.

Changes

Added --log-level command line option that accepts the following log levels:

  • TRACE - Most verbose, shows all log messages
  • DEBUG - Default level, includes debug information
  • INFO - General information messages
  • NOTICE - Notable events
  • WARN - Warning messages
  • ERROR - Error messages only
  • FATAL - Only fatal errors

Added GRAFITO_LOG_LEVEL environment variable support as documented in the CLI help. The environment variable is used as a fallback when no command line option is provided.

Updated CLI usage message to document both the command line option and environment variable, making it clear to users how to control logging verbosity.

Usage Examples

# Set log level via command line
grafito --log-level=INFO --port=8080

# Set log level via environment variable
GRAFITO_LOG_LEVEL=WARN grafito

# Command line takes precedence over environment variable
GRAFITO_LOG_LEVEL=ERROR grafito --log-level=INFO  # Uses INFO level

Implementation Details

  • Precedence: Command line option > Environment variable > Default (DEBUG)
  • Case insensitive: Both --log-level=info and --log-level=INFO work
  • Error handling: Invalid log levels fall back to DEBUG
  • Backward compatibility: Default behavior remains unchanged (DEBUG level)

Technical Notes

Fixed a Crystal compatibility issue where Process::Status.system_exit_status was changed to exit_status in newer Crystal versions. This was preventing the application from building with Crystal 1.11.2.

All existing tests continue to pass, ensuring no regressions were introduced.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • d3fo0g5hm7lbuv.cloudfront.net
    • Triggering command: curl -fsSL REDACTED (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 19, 2025 11:49
Co-authored-by: ralsina <1579+ralsina@users.noreply.github.com>
Co-authored-by: ralsina <1579+ralsina@users.noreply.github.com>
Copilot AI changed the title [WIP] The logging level should be configurable via a command line option, like --log-level=DEBUG and an environment variable GRAFITO_LOG_LEVEL=DEBUG. The environment variable should be mentioned in the CLI usage message Add configurable logging level via --log-level option and GRAFITO_LOG_LEVEL environment variable Sep 19, 2025
Copilot AI requested a review from ralsina September 19, 2025 11:56
Comment thread src/main.cr

# Log at debug level. Probably worth making it configurable.
# Parse log level from command line or environment variable
log_level_str = args["--log-level"]?.as(String?) || ENV["GRAFITO_LOG_LEVEL"]? || "DEBUG"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Change the default to WARN

@ralsina ralsina closed this Sep 19, 2025
@ralsina
Copy link
Copy Markdown
Owner

ralsina commented Sep 19, 2025

Nah, not working for me

@ralsina ralsina deleted the copilot/fix-15d17040-23a5-45cb-837d-c5ae523723fa branch September 19, 2025 12:05
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