Class: Lokii::Logger
- Inherits:
-
Object
- Object
- Lokii::Logger
- Defined in:
- lib/lokii/logger.rb
Overview
The Lokii Logger is inteded to give a simple logging interface that can be run in daemon mode or on a console. To use the logger, simply call the appropriate class method (usually debug or err):
Lokii::Logger.debug "I want to log this"
When running in daemon mode the output is only sent to the specified log file (and not the console). You can configure the output log file in config/settings.yml.
Constant Summary collapse
- @@logger =
nil
Class Method Summary collapse
-
.daemon? ⇒ Boolean
Checks the
LOKII_DAEMONconstant to determine if the logger should be run in daemon mode. - .logger ⇒ Object
- .logger=(value) ⇒ Object
- .method_missing(name, *args, &blk) ⇒ Object
-
.setup ⇒ Object
The setup method is called for each execution.
Class Method Details
.daemon? ⇒ Boolean
Checks the LOKII_DAEMON constant to determine if the logger should be run in daemon mode. The LOKII_DAEMON constant is initialized in the script/lokii daemon only.
41 42 43 |
# File 'lib/lokii/logger.rb', line 41 def daemon? defined?(LOKII_DAEMON) && LOKII_DAEMON end |
.logger ⇒ Object
17 18 19 |
# File 'lib/lokii/logger.rb', line 17 def logger @@logger end |
.logger=(value) ⇒ Object
21 22 23 |
# File 'lib/lokii/logger.rb', line 21 def logger=(value) @@logger = value end |
.method_missing(name, *args, &blk) ⇒ Object
25 26 27 28 29 |
# File 'lib/lokii/logger.rb', line 25 def method_missing(name, *args, &blk) self.setup self.logger.send(name, *args, &blk) puts(*args) unless daemon? || Lokii::Config.environment == :test end |
.setup ⇒ Object
The setup method is called for each execution. If the internal logger has not been created, it will be. This method should not be called directly.
33 34 35 36 |
# File 'lib/lokii/logger.rb', line 33 def setup self.logger.reopen(File.open(File.join(Lokii::Config.root, Lokii::Config.log), "a")) if daemon? && self.logger self.logger ||= ::Logger.new(File.join(Lokii::Config.root, Lokii::Config.log)) end |