Class: Bunyan::Logger

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/bunyan.rb,
lib/bunyan/config.rb

Defined Under Namespace

Classes: Config, InvalidConfigurationError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/bunyan.rb', line 46

def method_missing(method, *args, &block)
  begin
    collection.send(method, *args) if database_is_usable?
  rescue
    super(method, *args, &block)
  end
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



15
16
17
# File 'lib/bunyan.rb', line 15

def collection
  @collection
end

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/bunyan.rb', line 15

def config
  @config
end

#connectionObject (readonly)

Returns the value of attribute connection.



15
16
17
# File 'lib/bunyan.rb', line 15

def connection
  @connection
end

#dbObject (readonly)

Returns the value of attribute db.



15
16
17
# File 'lib/bunyan.rb', line 15

def db
  @db
end

Class Method Details

.method_missing(method, *args, &block) ⇒ Object

Pass all missing class methods to the singleton instance



55
56
57
# File 'lib/bunyan.rb', line 55

def self.method_missing(method, *args, &block)
  Logger.instance.send(method, *args, &block)
end

Instance Method Details

#configure(&block) ⇒ Object

Bunyan::Logger.configure do

# required options
database   'bunyan_logger'
collection 'development_log'

# optional options
disabled true
size 52428800 # 50.megabytes in Rails

end



26
27
28
29
30
31
32
33
34
35
# File 'lib/bunyan.rb', line 26

def configure(&block)
  @config = Logger::Config.new

  # provide legacy support for old configuration syntax
  (block.arity > 0) ? yield(@config) : @config.instance_eval(&block)

  ensure_required_options_exist
  initialize_connection unless disabled?
  @configured = true
end

#configured?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bunyan.rb', line 37

def configured?
  !!@configured
end

#disabled?Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/bunyan.rb', line 41

def disabled?
  # @TODO: Refactor this. Yuck.
  config.nil? || (!config.nil? && config.disabled?)
end