Module: LogJam
- Defined in:
- lib/logjam/logjam.rb,
lib/logjam/version.rb,
lib/logjam/exceptions.rb,
lib/logjam/logjam_logger.rb,
lib/logjam/logjam_logger2.rb
Overview
! /usr/bin/env ruby
Copyright ©, 2012 Peter Wood See the license.txt for details of the licensing of the code in this file.
Defined Under Namespace
Classes: LogJamError, LogJamLogger
Constant Summary collapse
- LOGGER_NAME =
Module constants.
:name
- LOGGER_FILE =
:file
- LOGGER_ROTATION =
:rotation
- LOGGER_MAX_SIZE =
:max_size
- LOGGER_LEVEL =
:level
- LOGGER_DEFAULT =
:default
- LOGGER_DATETIME_FORMAT =
:datetime_format
- DEFAULT_FILE_NAMES =
[".#{File::SEPARATOR}logging.yaml", ".#{File::SEPARATOR}logging.yml", ".#{File::SEPARATOR}logging.json", ".#{File::SEPARATOR}config#{File::SEPARATOR}logging.yaml", ".#{File::SEPARATOR}config#{File::SEPARATOR}logging.yml", ".#{File::SEPARATOR}config#{File::SEPARATOR}logging.json"]
- VERSION =
"1.1.0"
- @@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) ⇒ 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.
73 74 75 76 77 |
# File 'lib/logjam/logjam.rb', line 73 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) ⇒ Object
This method is used to configure the LogJam module with the various loggers it will use.
Parameters
- source
-
Either a String containing the path and name of the configuration file containing the logging set up, an IO object from which the configuration details can be read, a Hash containing a logging configuration or nil.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/logjam/logjam.rb', line 42 def self.configure(source) @@logjam_modules = {} @@logjam_loggers = {} # Check for default files if nil was passed in. source = LogJam.find_default_file if source.nil? if !source.kind_of?(Hash) && !source.nil? io = source.kind_of?(String) ? File.new(source) : source type = source.kind_of?(String) ? LogJam.guess_format(source) : nil LogJam.process_configuration(LogJam.load_configuration(io, type)) elsif source.nil? LogJam.process_configuration({}) else LogJam.process_configuration(source) end 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.
84 85 86 87 |
# File 'lib/logjam/logjam.rb', line 84 def self.get_logger(name=nil) LogJam.process_configuration(nil) 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.
91 92 93 |
# File 'lib/logjam/logjam.rb', line 91 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.
97 98 99 |
# File 'lib/logjam/logjam.rb', line 97 def log self.class.log end |