Skip to content

Commit

Permalink
#366: Add file appender with rolling options
Browse files Browse the repository at this point in the history
Fixed #366
  • Loading branch information
dgroup committed Apr 24, 2021
1 parent e486c85 commit f2b9d07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ services:
volumes:
- .local/dumps:/lazylead/dumps
- .local/logs:/lazylead/logs
entrypoint: bin/lazylead --trace --verbose
entrypoint: bin/lazylead --trace --verbose --log-file /lazylead/logs/ll{{.%Y-%m-%dT%H:%M:%S}}.log
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Layout/LineLength:
Exclude:
- "*.gemspec"
- "test/**/*"
- "bin/lazylead"

Metrics/AbcSize:
Max: 21
Expand Down
3 changes: 3 additions & 0 deletions bin/lazylead
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Available options:"
o.bool "--testdata",
"Apply the database VCS migration with test data",
default: false
o.string "--log-file", "The path to the log file"
o.string "--rolling-age", "The maximum age (in seconds) of a log file before it is rolled. The age can also be given as 'daily', 'weekly', or 'monthly'"
o.string "--rolling-files", "The number of rolled log files to keep."
o.on "--verbose", "Enable extra logging information" do
log.verbose
end
Expand Down
11 changes: 11 additions & 0 deletions lib/lazylead/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ module Level
)
)

if ARGV.include? "--log-file"
name = ARGV[ARGV.find_index("--log-file") + 1]
age = "daily"
age = ARGV[ARGV.find_index("--rolling-age") + 1] if ARGV.include? "--rolling-age"
files = 7
files = ARGV[ARGV.find_index("--rolling-files") + 1] if ARGV.include? "--rolling-files"
FILE_APPENDER = Logging.appenders.rolling_file("file", filename: name, age: age, keep: files)
end

# Nothing to log
NOTHING = Logging.logger["nothing"]
NOTHING.level = :off
Expand All @@ -83,12 +92,14 @@ module Level
DEBUG = Logging.logger["debug"]
DEBUG.level = :debug
DEBUG.add_appenders "stdout"
DEBUG.add_appenders(FILE_APPENDER) if ARGV.include? "--log-file"
DEBUG.freeze

# Alerts/errors
ERRORS = Logging.logger["errors"]
ERRORS.level = :error
ERRORS.add_appenders "stdout"
ERRORS.add_appenders(FILE_APPENDER) if ARGV.include? "--log-file"
ERRORS.freeze
end
end

0 comments on commit f2b9d07

Please sign in to comment.