module Hatchet

Public: Hatchet is a library for providing logging facilities whose levels are configurable to the class and module level.

It also provides the facility to have several appenders added to from a single log call with each appender capable of being configured to log at different levels.

Hatchet provides no logging implementations of its own. Instead it delegates to the standard Logger within the reference LoggerAppender implementation.

Constants

VERSION

Public: The version of Hatchet.

Public Class Methods

appenders() click to toggle source

Internal: Returns the Array of configured appenders.

# File lib/hatchet.rb, line 155
def self.appenders
  configuration.appenders
end
configuration() click to toggle source

Internal: Returns the configuration object, initializing it when necessary.

# File lib/hatchet.rb, line 161
def self.configuration
  @config ||= Configuration.new
end
configure(&block) click to toggle source

Public: Method for configuring Hatchet.

block - Mandatory block which receives a Configuration object that can be

used to setup Hatchet.

Once the block returns each of the configured appenders has its formatter set as a StandardFormatter if one is not already set, and its levels Hash is set to the shared levels Hash if an explicit one has not been provided.

Example

Hatchet.configure do |config|
  # Set the level to use unless overridden (defaults to :info)
  config.level :info
  # Set the level for a specific class/module and its children
  config.level :debug, 'Namespace::Something::Nested'

  # Add as many appenders as you like
  config.appenders << Hatchet::LoggerAppender.new do |appender|
    # Set the logger that this is wrapping (required)
    appender.logger = Logger.new('log/test.log')
  end
end

Returns nothing.

# File lib/hatchet.rb, line 137
def self.configure(&block)
  configuration.configure(&block)
end
included(klass) click to toggle source

Internal: Hook that extends the class with Hatchet when it is included.

klass - The klass that Hatchet was included into.

Returns nothing.

# File lib/hatchet.rb, line 171
def self.included(klass)
  klass.extend Hatchet
end
registered(app) click to toggle source

Public: Callback method for when Hatchet is registered as a Sinatra helper.

Example

register Hatchet

Returns nothing.

# File lib/hatchet.rb, line 149
def self.registered(app)
  app.helpers Hatchet
end

Public Instance Methods

log()

Public: Returns a HatchetLogger for the object.

The logger has 5 logging methods. Those are, in decreasing order of severity:

* fatal
* error
* warn
* info
* debug

All these methods have the same signature. You can either provide a message as a direct string, or as a block to the method is lazily evaluated (this is the recommended option).

Examples

log.info "Informational message"
log.info { "Informational message #{potentially_expensive}" }

Log messages are sent to each appender where they will be filtered and invoked as configured.

The logger also has 5 inspection methods. Those are, in decreasing order of severity:

* fatal?
* error?
* warn?
* info?
* debug?

All these methods take no arguments and return true if any of the loggers' appenders will log a message at that level for the current context, otherwise they will return false.

Returns a HatchetLogger for the object.

Alias for: logger
logger() click to toggle source

Public: Returns a HatchetLogger for the object.

The logger has 5 logging methods. Those are, in decreasing order of severity:

* fatal
* error
* warn
* info
* debug

All these methods have the same signature. You can either provide a message as a direct string, or as a block to the method is lazily evaluated (this is the recommended option).

Examples

logger.info "Informational message"
logger.info { "Informational message #{potentially_expensive}" }

Log messages are sent to each appender where they will be filtered and invoked as configured.

The logger also has 5 inspection methods. Those are, in decreasing order of severity:

* fatal?
* error?
* warn?
* info?
* debug?

All these methods take no arguments and return true if any of the loggers' appenders will log a message at that level for the current context, otherwise they will return false.

Returns a HatchetLogger for the object.

# File lib/hatchet.rb, line 67
def logger
  @_hatchet_logger ||= HatchetLogger.new(self, Hatchet.configuration, Hatchet::NestedDiagnosticContext.current)
end
Also aliased as: log
to_yaml_properties() click to toggle source

Internal: Definition to avoid the cache variable from being persisted when an instance including Hatchet is marshalled into YAML.

Calls superclass method
# File lib/hatchet.rb, line 178
def to_yaml_properties
  super - [:@_hatchet_logger]
end