Class: ComposableAgents::Logger
- Inherits:
-
Logger
- Object
- Logger
- ComposableAgents::Logger
- Defined in:
- lib/composable_agents/logger.rb
Overview
Logger to be used by agents. This is a standard Ruby Logger (inheriting from ::Logger) that formats messages with a UTC timestamp and severity. It also supports prefixing fields to messages (like the agent's full name) using the #tagged method, which returns a proxy compatible with any Ruby-like logger: fields are then prepended to the logged messages themselves, and silently ignored by loggers not supporting them.
Defined Under Namespace
Classes: Tagged
Class Method Summary collapse
-
.instance ⇒ Logger
Get the default singleton logger instance.
Instance Method Summary collapse
-
#initialize(logdev = $stdout, *args, **kwargs) ⇒ Logger
constructor
Constructor.
-
#tagged(*fields) ⇒ Tagged
Get a logger proxy that prefixes the given fields to logged messages.
Constructor Details
#initialize(logdev = $stdout, *args, **kwargs) ⇒ Logger
Constructor.
Unless overridden by the caller, the default level follows the COMPOSABLE_AGENTS_DEBUG environment variable
(DEBUG when it is set to 1, INFO otherwise), and the default formatter outputs messages as
[UTC timestamp] [SEVERITY] message.
29 30 31 32 33 34 35 36 37 |
# File 'lib/composable_agents/logger.rb', line 29 def initialize(logdev = $stdout, *args, **kwargs) super self.level = ENV['COMPOSABLE_AGENTS_DEBUG'] == '1' ? DEBUG : INFO unless kwargs.key?(:level) return if kwargs.key?(:formatter) self.formatter = proc do |severity, _datetime, _progname, | "[#{Time.now.utc.strftime('%F %T')}] [#{severity}] #{}\n" end end |
Class Method Details
.instance ⇒ Logger
Get the default singleton logger instance
16 17 18 |
# File 'lib/composable_agents/logger.rb', line 16 def instance @instance ||= new end |