Module: Logger
- Included in:
- Kffpt::Main
- Defined in:
- lib/kffpt/logger.rb
Instance Method Summary collapse
- #debug(m) ⇒ Object
- #info(m) ⇒ Object
- #log(message, level) ⇒ Object
- #out ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
- #trace(m) ⇒ Object
Instance Method Details
#debug(m) ⇒ Object
47 48 49 |
# File 'lib/kffpt/logger.rb', line 47 def debug m stderr.puts blue(log(m, 'DEBUG')) if [:debug] end |
#info(m) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/kffpt/logger.rb', line 39 def info m if [:debug] || [:trace] stdout.puts green(log(m, 'INFO')) else stdout.puts green(m) end end |
#log(message, level) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/kffpt/logger.rb', line 9 def log , level '%s [%s] %s -- %s' % [ level, Time.now.iso8601(6), File::basename(caller[4]), ] end |
#out ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kffpt/logger.rb', line 18 def out begin @@log rescue NameError started = File.exist? [:log] @@log = File.open [:log], 'a' @@log.puts '# Log started %s' % Time.now unless started @@log end end |
#stderr ⇒ Object
29 30 31 32 |
# File 'lib/kffpt/logger.rb', line 29 def stderr return out if [:log] $stderr end |
#stdout ⇒ Object
34 35 36 37 |
# File 'lib/kffpt/logger.rb', line 34 def stdout return out if [:log] $stdout end |
#trace(m) ⇒ Object
51 52 53 |
# File 'lib/kffpt/logger.rb', line 51 def trace m stderr.puts magenta(log(m, 'TRACE')) if [:trace] end |