Class: Bunyan::Logger
- Inherits:
-
Object
- Object
- Bunyan::Logger
- Includes:
- Singleton
- Defined in:
- lib/bunyan.rb,
lib/bunyan/config.rb
Defined Under Namespace
Classes: Config, InvalidConfigurationError
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Class Method Summary collapse
-
.method_missing(method, *args, &block) ⇒ Object
Pass all missing class methods to the singleton instance.
Instance Method Summary collapse
-
#configure(&block) ⇒ Object
Bunyan::Logger.configure do # required options database ‘bunyan_logger’ collection ‘development_log’.
- #configured? ⇒ Boolean
- #disabled? ⇒ Boolean
- #method_missing(method, *args, &block) ⇒ Object
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
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
15 16 17 |
# File 'lib/bunyan.rb', line 15 def collection @collection end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/bunyan.rb', line 15 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
15 16 17 |
# File 'lib/bunyan.rb', line 15 def connection @connection end |
#db ⇒ Object (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) initialize_connection unless disabled? @configured = true end |
#configured? ⇒ Boolean
37 38 39 |
# File 'lib/bunyan.rb', line 37 def configured? !!@configured end |
#disabled? ⇒ Boolean
41 42 43 44 |
# File 'lib/bunyan.rb', line 41 def disabled? # @TODO: Refactor this. Yuck. config.nil? || (!config.nil? && config.disabled?) end |