diff --git a/doc/config/environment-variables.md b/doc/config/environment-variables.md index 56fc70a..e287459 100644 --- a/doc/config/environment-variables.md +++ b/doc/config/environment-variables.md @@ -43,6 +43,7 @@ This document contains all the environment variables which are available for thi | `LOGGING_RAILS_LOG_ENABLED` | Boolean | Enable the default Rails logger | false | | `LOGGING_SENTRY_DSN` | String | A DSN which should be used to report exceptions to Sentry | | | `LOGGING_ENABLED` | Boolean | Enable the Postal logger to log to STDOUT | true | +| `LOGGING_LEVEL` | String | The minimum log level for the Postal logger (debug, info, warn, error, fatal) | INFO | | `LOGGING_HIGHLIGHTING_ENABLED` | Boolean | Enable highlighting of log lines | false | | `GELF_HOST` | String | GELF-capable host to send logs to | | | `GELF_PORT` | Integer | GELF port to send logs to | 12201 | diff --git a/doc/config/yaml.yml b/doc/config/yaml.yml index 4e0406d..a91c303 100644 --- a/doc/config/yaml.yml +++ b/doc/config/yaml.yml @@ -89,6 +89,8 @@ logging: sentry_dsn: # Enable the Postal logger to log to STDOUT enabled: true + # The minimum log level for the Postal logger (debug, info, warn, error, fatal) + level: INFO # Enable highlighting of log lines highlighting_enabled: false diff --git a/lib/postal/config.rb b/lib/postal/config.rb index d118e77..186f6de 100644 --- a/lib/postal/config.rb +++ b/lib/postal/config.rb @@ -83,6 +83,7 @@ module Postal def logger @logger ||= begin k = Klogger.new(nil, destination: Config.logging.enabled? ? $stdout : "/dev/null", highlight: Config.logging.highlighting_enabled?) + k.level = Config.logging.level k.add_destination(graylog_logging_destination) if Config.gelf.host.present? k end diff --git a/lib/postal/config_schema.rb b/lib/postal/config_schema.rb index 871d094..241d627 100644 --- a/lib/postal/config_schema.rb +++ b/lib/postal/config_schema.rb @@ -227,6 +227,19 @@ module Postal default true end + string :level do + description "The minimum log level for the Postal logger (debug, info, warn, error, fatal)" + default "INFO" + transform do |value| + normalized = value.to_s.strip.downcase + normalized = "info" if normalized.empty? + unless %w[debug info warn error fatal].include?(normalized) + raise ArgumentError, "logging.level must be one of: debug, info, warn, error, fatal (got #{value.inspect})" + end + normalized + end + end + boolean :highlighting_enabled do description "Enable highlighting of log lines" default false