Module: Notarius

Defined in:
lib/notarius.rb,
lib/notarius/config.rb,
lib/notarius/version.rb,
lib/notarius/formatter.rb,
lib/notarius/secretary.rb

Overview

Notarius is a logging library with opinions.

Defined Under Namespace

Classes: Config, Formatter, Secretary

Constant Summary collapse

VERSION =

Semantic versioning makes life easier.

'0.2.6'

Class Method Summary collapse

Class Method Details

.config(name) ⇒ Config?

Gets the configuration for a module.

Parameters:

  • name (String)

    the module’s name

Returns:

  • (Config, nil)

    the module’s configuration or nil if none was found



48
49
50
51
# File 'lib/notarius.rb', line 48

def self.config name
  validate name
  @configs[name]
end

.configure(name) {|log| ... } ⇒ void

This method returns an undefined value.

Configures a logging module. If a matching module exists, it will be reconfigured. Otherwise, a new module will be created.

Examples:

Notarius.configure 'BIG' do |log|
  log.console = true
  log.file = '/var/log/notarius/big.log'
end

Parameters:

  • name (#to_s)

    the module’s name

Yield Parameters:

  • log (Config)

    the module’s configuration



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/notarius.rb', line 25

def self.configure name, &block
  name = namespace name
  @configs[name] ||= Config.new
  block.call @configs[name] if block
  return if self.const_defined? name

  mod = Module.new do
    define_method :log do
      @secretary ||= Secretary.new
      @secretary.configure Notarius.config(name)
      @secretary
    end
  end
  self.const_set name, mod
end