Skip to content

Commit

Permalink
[#457] Inform the user of misconfigured log_level debug value
Browse files Browse the repository at this point in the history
If the user set the `log_level = debugX` with X being a number outside
of the valid range 1-5, the application adjusts the logging level to
the upper or lower boundary, now informing the user that her
configuration has been ignored.

Documentation updated.

Also adds `trace` as a synonim for `debug5`.

Close #457
  • Loading branch information
fluca1978 committed Aug 22, 2024
1 parent 5fae10c commit 345fde7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The available keys and their accepted values are reported in the table below.
| metrics_cache_max_size | 256k | String | No | The maximum amount of data to keep in cache when serving Prometheus responses. Changes require restart. This parameter determines the size of memory allocated for the cache even if `metrics_cache_max_age` or `metrics` are disabled. Its value, however, is taken into account only if `metrics_cache_max_age` is set to a non-zero value. Supports suffixes: 'B' (bytes), the default if omitted, 'K' or 'KB' (kilobytes), 'M' or 'MB' (megabytes), 'G' or 'GB' (gigabytes).|
| management | 0 | Int | No | The remote management port (disable = 0) |
| log_type | console | String | No | The logging type (console, file, syslog) |
| log_level | info | String | No | The logging level, any of the (case insensitive) strings `FATAL`, `ERROR`, `WARN`, `INFO` and `DEBUG` (that can be more specific as `DEBUG1` thru `DEBUG5`). Debug level greater than 5 will be set to `DEBUG5`. Not recognized values will make the log_level be `INFO` |
| log_level | info | String | No | The logging level, any of the (case insensitive) strings `FATAL`, `ERROR`, `WARN`, `INFO`, `DEBUG` and `TRACE`. The `DEBUG` keyword can be more specific such as `DEBUG1` up to `DEBUG5`; higher numbers mean higher verbosity. Debug level greater than 5 will be set to `DEBUG5`, while levels lower than 1 will be set to `DEBUG1`, and the application will raise a warning about the ignored value. The word `TRACE` is a synonim for `DEBUG5`. Not recognized values will make the log_level be `INFO` |
| log_path | pgagroal.log | String | No | The log file location. Can be a strftime(3) compatible string. |
| log_rotation_age | 0 | String | No | The age that will trigger a log file rotation. If expressed as a positive number, is managed as seconds. Supports suffixes: 'S' (seconds, the default), 'M' (minutes), 'H' (hours), 'D' (days), 'W' (weeks). A value of `0` disables. |
| log_rotation_size | 0 | String | No | The size of the log file that will trigger a log rotation. Supports suffixes: 'B' (bytes), the default if omitted, 'K' or 'KB' (kilobytes), 'M' or 'MB' (megabytes), 'G' or 'GB' (gigabytes). A value of `0` (with or without suffix) disables. |
Expand Down
12 changes: 12 additions & 0 deletions src/libpgagroal/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,12 @@ as_logging_level(char* str)
free(debug_value);
}

if (debug_level < 1 || debug_level > 5)
{
warnx("Log level debug configuration %d not understood: %s - resetting to none", debug_level, str);
debug_level = 1;
}

if (debug_level <= 1)
{
return PGAGROAL_LOGGING_LEVEL_DEBUG1;
Expand Down Expand Up @@ -2288,6 +2294,12 @@ as_logging_level(char* str)
return PGAGROAL_LOGGING_LEVEL_FATAL;
}

// "trace" is a synonim for "debug5"
if (!strcasecmp(str, "trace"))
{
return PGAGROAL_LOGGING_LEVEL_DEBUG5;
}

return PGAGROAL_LOGGING_LEVEL_INFO;
}

Expand Down

0 comments on commit 345fde7

Please sign in to comment.