Module: LogJam
- Defined in:
- lib/logjam/logger.rb,
lib/logjam.rb,
lib/logjam/version.rb,
lib/logjam/exceptions.rb,
lib/logjam/configuration.rb
Overview
! /usr/bin/env ruby
Copyright ©, 2015 Peter Wood See the license.txt for details of the licensing of the code in this file.
Defined Under Namespace
Classes: Configuration, Error, Logger
Constant Summary collapse
- LEVEL_MAP =
Module constants.
{"debug" => Logger::DEBUG, "info" => Logger::INFO, "warn" => Logger::WARN, "error" => Logger::ERROR, "fatal" => Logger::FATAL, "unknown" => Logger::UNKNOWN}
- STREAM_MAP =
{"stdout" => STDOUT, "stderr" => STDERR}
- VERSION =
"1.2.3"
- @@logjam_modules =
Module static properties.
{}
- @@logjam_loggers =
{}
- @@logjam_contexts =
{}
Class Method Summary collapse
-
.apply(target, name = nil, context = {}) ⇒ Object
This method is used to install logging facilities at the class level for a given class.
-
.configure(source = nil) ⇒ Object
This method is used to configure the LogJam module with the various loggers it will use.
-
.get_logger(name = nil) ⇒ Object
This method attempts to fetch the logger for a specified name.
-
.names ⇒ Object
This method fetches a list of the names currently defined within the LogJam internal settings.
Instance Method Summary collapse
-
#log ⇒ Object
A convenience mechanism that provides an instance level access to the class level logger.
Class Method Details
.apply(target, name = nil, context = {}) ⇒ Object
This method is used to install logging facilities at the class level for a given class. Once ‘logified’ a class will possess two new methods. The first, #log(), retrieves the logger associated with the class. The second, #log=(), allows the assignment of the logger associated with the class. Note that changing the logger associated with a class will impact all other classes that use the same logger.
Parameters
- target
-
The target class that is to be extended.
- name
-
The name of the logger to be used by the class. Defaults to nil to indicate use of the default logger.
- context
-
A Hash of additional parameters that are specific to the class to which LogJam is being applied.
56 57 58 59 60 |
# File 'lib/logjam.rb', line 56 def self.apply(target, name=nil, context={}) @@logjam_contexts[target] = {}.merge(context) target.extend(LogJam.get_module(name, @@logjam_contexts[target])) target.send(:define_method, :log) {LogJam.get_logger(name)} if !target.method_defined?(:log) end |
.configure(source = nil) ⇒ Object
This method is used to configure the LogJam module with the various loggers it will use.
Parameters
- source
-
Either a Hash containing the configuration to be used or nil to indicate the use of default configuration settings.
37 38 39 40 41 |
# File 'lib/logjam.rb', line 37 def self.configure(source=nil) @@logjam_modules = {} @@logjam_loggers = {} LogJam.process_configuration(source ? source : Configuration.instance) end |
.get_logger(name = nil) ⇒ Object
This method attempts to fetch the logger for a specified name. If this logger does not exist then a default logger will be returned instead.
Parameters
- name
-
The name of the logger to retrieve.
67 68 69 70 |
# File 'lib/logjam.rb', line 67 def self.get_logger(name=nil) LogJam.process_configuration(Configuration.instance) if @@logjam_loggers.empty? @@logjam_loggers.fetch(name, @@logjam_loggers[nil]) end |
.names ⇒ Object
This method fetches a list of the names currently defined within the LogJam internal settings.
74 75 76 |
# File 'lib/logjam.rb', line 74 def self.names @@logjam_loggers.keys.compact end |
Instance Method Details
#log ⇒ Object
A convenience mechanism that provides an instance level access to the class level logger.
80 81 82 |
# File 'lib/logjam.rb', line 80 def log self.class.log end |