Module: Waves::Logger
- Defined in:
- lib/runtime/logger.rb
Overview
Waves::Logger is based on Ruby’s built-in Logger. It uses the same filtering approach (debug, info, warn, error, fatal), although the interface is slightly different. You won’t typically instantiate this class directly; instead, you will specify the logging configuration you want in your configuration files. See Waves::Configurations for more information on this.
To use the logger for output, you can usually just call log
, since the Waves::ResponseHelper mixin defines it (meaning it is available in the mapping file, controllers, views, and templates). Or, you can access Waves::Logger directly. Either way, the logger provides five methods for output corresponding to the log levels.
Examples
# log the value of foo
log.info "Value of foo: #{foo}"
# fatal error!
Waves::Logger.fatal "She can't hold up any longer, cap'n!"
Class Method Summary collapse
-
.config ⇒ Object
Returns the active configuration for the logger.
-
.level ⇒ Object
Returns the logging level used to filter logging events.
-
.method_missing(name, *args, &block) ⇒ Object
Forwards logging methods to the logger.
-
.output ⇒ Object
Returns the object being used for output by the logger.
-
.start ⇒ Object
Starts the logger, using the active configuration to initialize it.
Class Method Details
.config ⇒ Object
Returns the active configuration for the logger.
32 33 34 |
# File 'lib/runtime/logger.rb', line 32 def config @config ||= Waves::Server.config.log end |
.level ⇒ Object
Returns the logging level used to filter logging events.
37 |
# File 'lib/runtime/logger.rb', line 37 def level ; @level ||= ::Logger.const_get( config[:level].to_s.upcase || 'INFO' ) ; end |
.method_missing(name, *args, &block) ⇒ Object
Forwards logging methods to the logger.
50 51 52 |
# File 'lib/runtime/logger.rb', line 50 def method_missing(name,*args,&block) @log.send name,*args, &block if @log end |
.output ⇒ Object
Returns the object being used for output by the logger.
27 28 29 |
# File 'lib/runtime/logger.rb', line 27 def output @output ||= ( config[:output] ? File.( config[:output] ) : $stderr ) end |
.start ⇒ Object
Starts the logger, using the active configuration to initialize it.
40 41 42 43 44 45 46 47 |
# File 'lib/runtime/logger.rb', line 40 def start @log = config[:rotation] ? ::Logger.new( output, config[:rotation].intern ) : ::Logger.new( output ) @log.level = level @log.datetime_format = "%Y-%m-%d %H:%M:%S " self end |