-
-
Notifications
You must be signed in to change notification settings - Fork 402
Adds log level option and configuration via environment in scripts. #271
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ services: | |
| - TZ=${TZ:-America/Sao_Paulo} | ||
| - WEBHOOK_FORMAT=${WEBHOOK_FORMAT:-json} | ||
| - SESSION_DEVICE_NAME=${SESSION_DEVICE_NAME:-WuzAPI} | ||
| - LOG_LEVEL=info | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| # RabbitMQ configuration Optional | ||
| - RABBITMQ_URL=amqp://wuzapi:wuzapi@rabbitmq:5672/ | ||
| - RABBITMQ_QUEUE=whatsapp_events | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -49,6 +49,7 @@ var ( | |||||||||||||
| port = flag.String("port", "8080", "Listen Port") | ||||||||||||||
| waDebug = flag.String("wadebug", "", "Enable whatsmeow debug (INFO or DEBUG)") | ||||||||||||||
| logType = flag.String("logtype", "console", "Type of log output (console or json)") | ||||||||||||||
| logLevel = flag.String("loglevel", "info", "Log level (debug, info, warn, error)") | ||||||||||||||
| skipMedia = flag.Bool("skipmedia", false, "Do not attempt to download media in messages") | ||||||||||||||
| osName = flag.String("osname", "Mac OS 10", "Connection OSName in Whatsapp") | ||||||||||||||
| colorOutput = flag.Bool("color", false, "Enable colored output for console logs") | ||||||||||||||
|
|
@@ -180,6 +181,28 @@ func main() { | |||||||||||||
|
|
||||||||||||||
| flag.Parse() | ||||||||||||||
|
|
||||||||||||||
| // Configure log level from environment variable if set | ||||||||||||||
| if v := os.Getenv("LOG_LEVEL"); v != "" { | ||||||||||||||
| *logLevel = v | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+185
to
+187
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| // Set global log level | ||||||||||||||
| switch strings.ToLower(*logLevel) { | ||||||||||||||
| case "debug": | ||||||||||||||
| zerolog.SetGlobalLevel(zerolog.DebugLevel) | ||||||||||||||
| log.Debug().Msg("Log level set to DEBUG") | ||||||||||||||
| case "info": | ||||||||||||||
| zerolog.SetGlobalLevel(zerolog.InfoLevel) | ||||||||||||||
| case "warn", "warning": | ||||||||||||||
| zerolog.SetGlobalLevel(zerolog.WarnLevel) | ||||||||||||||
| case "error": | ||||||||||||||
| zerolog.SetGlobalLevel(zerolog.ErrorLevel) | ||||||||||||||
| default: | ||||||||||||||
| zerolog.SetGlobalLevel(zerolog.InfoLevel) | ||||||||||||||
| log.Warn().Str("invalid_level", *logLevel).Msg("Invalid log level, defaulting to INFO") | ||||||||||||||
| *logLevel = "info" | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Check for address in environment variable if flag is default or empty | ||||||||||||||
| if *address == "0.0.0.0" || *address == "" { | ||||||||||||||
| if v := os.Getenv("WUZAPI_ADDRESS"); v != "" { | ||||||||||||||
|
|
||||||||||||||
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.
The
LOG_LEVELis 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}