-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(BOLT-523) Proxy r10k logs to the bolt logger
This introduces a proxy outputter for log4r that redirects all the log messages back to the bolt logger, where they can be sorted and handled in the standard way.
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'log4r/outputter/outputter' | ||
|
||
module Bolt | ||
class R10KLogProxy < Log4r::Outputter | ||
def initialize | ||
super('bolt') | ||
|
||
@logger = Logging.logger[self] | ||
end | ||
|
||
def canonical_log(event) | ||
level = to_bolt_level(event.level) | ||
@logger.send(level, event.data) | ||
end | ||
|
||
# Convert an r10k log level to a bolt log level. These correspond 1-to-1 | ||
# except that r10k has debug, debug1, and debug2. The log event has the log | ||
# level as an integer that we need to look up. | ||
def to_bolt_level(level_num) | ||
level_str = Log4r::LNAMES[level_num]&.downcase || 'debug' | ||
if level_str =~ /debug/ | ||
:debug | ||
else | ||
level_str.to_sym | ||
end | ||
end | ||
end | ||
end |