Class: GlobaLog
- Inherits:
-
Logger
- Object
- Logger
- GlobaLog
- Defined in:
- lib/globalog_runsync.rb,
lib/globalog.rb,
lib/globalog_args.rb,
lib/globalog_hijack.rb
Overview
- Author
-
lp ([email protected])
- Copyright
-
2009 Louis-Philippe Perron - Released under the terms of the MIT license
Defined Under Namespace
Class Method Summary collapse
-
.level ⇒ Object
The GlobaLog::level method return the current log level.
-
.logger(def_out, def_level, opt1 = :empty, opt2 = :empty, opt3 = :empty) ⇒ Object
The GlobaLog.logger acts as a constructor method for the logger.
-
.logger_params ⇒ Object
The GlobaLog::logger_params method return the current full Logger parameter arguments.
-
.options ⇒ Object
The GlobaLog::options method return the current extra Logger options.
-
.output ⇒ Object
The GlobaLog::output method return the current log output.
Instance Method Summary collapse
- #debug(arg, &block) ⇒ Object
- #error(arg, &block) ⇒ Object
- #fatal(arg, &block) ⇒ Object
- #info(arg, &block) ⇒ Object
- #unknown(arg, &block) ⇒ Object
- #warn(arg, &block) ⇒ Object
Class Method Details
.level ⇒ Object
The GlobaLog::level method return the current log level. Can be used to chain existing Logger instances to GlobaLog cascade, when you don’t want to replace them with GlobaLog instances. (and you can only replace the constructor, the logging will still work)
Example
$logger.level = GlobaLog::level
118 119 120 |
# File 'lib/globalog.rb', line 118 def GlobaLog::level Args::log_level end |
.logger(def_out, def_level, opt1 = :empty, opt2 = :empty, opt3 = :empty) ⇒ Object
The GlobaLog.logger acts as a constructor method for the logger.
Parameters
-
def_out = the output io or logfile path
-
def_level = the log level, as a symbol (i.e. :warn, :info, etc)
-
opt1, opt2 = (optional) logger extra log rotation parameters (see Logger rdoc for more details)
-
master = (optional) the logger presence in the cascading settings chain
master can be any of the following:
-
true = Impose its settings on the loggers down the chain
-
false = Use the chain settings if present (default)
-
nil = Is out of the chain
Example
@log = GlobaLog.logger(‘logfile.txt’,:error,true)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/globalog.rb', line 80 def GlobaLog.logger(def_out,def_level, opt1= :empty, opt2= :empty, opt3= :empty) logger_opts = []; master = false [opt1,opt2,opt3].each do |opt| if opt == :empty next elsif opt == true || opt == false || opt == nil master = opt else logger_opts << opt end end Args.are({:log_output => def_out, :log_level => def_level, :log_opts => logger_opts},master) if master.nil? log = self.new(def_out,*logger_opts) log.level = Args.sym_to_level(def_level) else log = self.new(Args::log_output,*logger_opts) log.level = Args::log_level end return log end |
.logger_params ⇒ Object
The GlobaLog::logger_params method return the current full Logger parameter arguments. They are returned as array so must be splatted before they are usefull for classic Logger initialization.
Example
$logger = Logger.new(*GlobaLog::logger_params)
135 136 137 |
# File 'lib/globalog.rb', line 135 def GlobaLog::logger_params return Args::log_output, *Args::log_opts end |
.options ⇒ Object
The GlobaLog::options method return the current extra Logger options. i.e. Log rotations, size, etc. They are returned as array so must be splatted before they are usefull for classic Logger initialization.
Example
$logger = Logger.new(GlobaLog::output,*GlobaLog::options)
127 128 129 |
# File 'lib/globalog.rb', line 127 def GlobaLog:: Args::log_opts end |
.output ⇒ Object
The GlobaLog::output method return the current log output. Can be used to chain existing Logger instances to GlobaLog cascade, when you don’t want to replace them with GlobaLog instances. (and you can only replace the constructor, the logging will still work)
Example
$logger = Logger.new(GlobaLog::output)
108 109 110 |
# File 'lib/globalog.rb', line 108 def GlobaLog::output Args::log_output end |
Instance Method Details
#debug(arg, &block) ⇒ Object
5 6 7 |
# File 'lib/globalog_runsync.rb', line 5 def debug(arg,&block) sync_level(:debug) { super(arg,&block) } end |
#error(arg, &block) ⇒ Object
17 18 19 |
# File 'lib/globalog_runsync.rb', line 17 def error(arg,&block) sync_level(:error) { super(arg,&block) } end |
#fatal(arg, &block) ⇒ Object
21 22 23 |
# File 'lib/globalog_runsync.rb', line 21 def fatal(arg,&block) sync_level(:fatal) { super(arg,&block) } end |
#info(arg, &block) ⇒ Object
9 10 11 |
# File 'lib/globalog_runsync.rb', line 9 def info(arg,&block) sync_level(:info) { super(arg,&block) } end |
#unknown(arg, &block) ⇒ Object
25 26 27 |
# File 'lib/globalog_runsync.rb', line 25 def unknown(arg,&block) sync_level(:unknown) { super(arg,&block) } end |
#warn(arg, &block) ⇒ Object
13 14 15 |
# File 'lib/globalog_runsync.rb', line 13 def warn(arg,&block) sync_level(:warn) { super(arg,&block) } end |