Class: RBus::Log
- Inherits:
-
Object
- Object
- RBus::Log
- Defined in:
- lib/rbus/etc/log.rb
Overview
A Logger based Log system, with levels. See Logger for more info.
RBus::Log logs to STDOUT by default, it’s possible to redirect this output to a file by setting a filename in the environment variable $RBUS_LOG_FILE. The default log level is ERROR, this can be adjusted by setting the environment variable $RBUS_LOG_LEVEL to FATAL, ERROR, WARN, INFO or DEBUG, or by setting RBus::Log.level=(new_level)
Constant Summary collapse
- @@logger =
Logger.new(log_target)
Class Method Summary collapse
- .debug(*objs) ⇒ Object
- .error(*objs) ⇒ Object
- .fatal(*objs) ⇒ Object
- .info(*objs) ⇒ Object
-
.level=(new_level) ⇒ Object
Set a new log level.
- .pp(*objs) ⇒ Object
- .warn(*objs) ⇒ Object
Class Method Details
.debug(*objs) ⇒ Object
83 84 85 |
# File 'lib/rbus/etc/log.rb', line 83 def self.debug(*objs) @@logger.debug(pp(objs)) end |
.error(*objs) ⇒ Object
71 72 73 |
# File 'lib/rbus/etc/log.rb', line 71 def self.error(*objs) @@logger.error(pp(objs)) end |
.fatal(*objs) ⇒ Object
87 88 89 |
# File 'lib/rbus/etc/log.rb', line 87 def self.fatal(*objs) @@logger.fatal(pp(objs)) end |
.info(*objs) ⇒ Object
79 80 81 |
# File 'lib/rbus/etc/log.rb', line 79 def self.info(*objs) @@logger.info(pp(objs)) end |
.level=(new_level) ⇒ Object
Set a new log level. Takes either a symbol, like :ERROR or a string, like ‘FATAL’.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rbus/etc/log.rb', line 42 def self.level=(new_level) new_level = new_level.to_s log_level = case new_level when 'FATAL' Logger::FATAL when 'ERROR' Logger::ERROR when 'WARN' Logger::WARN when 'INFO' Logger::INFO when 'DEBUG' Logger::DEBUG else Logger::ERROR end @@logger.level = log_level end |
.pp(*objs) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/rbus/etc/log.rb', line 61 def self.pp(*objs) sio = StringIO.new('') sio.write(caller(2)[0]) sio.write("\n") objs.each do |obj| PP.pp(obj,sio) end sio.string end |
.warn(*objs) ⇒ Object
75 76 77 |
# File 'lib/rbus/etc/log.rb', line 75 def self.warn(*objs) @@logger.warn(pp(objs)) end |