Class: Typhon::Log
- Inherits:
-
Object
- Object
- Typhon::Log
- Includes:
- Syslog::Constants
- Defined in:
- lib/typhon/log.rb
Class Method Summary collapse
- .configure ⇒ Object
-
.from ⇒ Object
figures out the filename that called us.
- .log(msg, severity = :debug) ⇒ Object
- .method_missing(level, *args, &block) ⇒ Object
- .valid_levels ⇒ Object
Class Method Details
.configure ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/typhon/log.rb', line 23 def configure Syslog.close if Syslog.opened? Syslog.open(File.basename($0)) @active_level = Config[:loglevel] raise "Unknown log level #{@active_level} specified" unless valid_levels.include?(@active_level) @configured = true end |
.from ⇒ Object
figures out the filename that called us
35 36 37 |
# File 'lib/typhon/log.rb', line 35 def from from = File.basename(caller[4]) end |
.log(msg, severity = :debug) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/typhon/log.rb', line 12 def log(msg, severity=:debug) configure unless @configured if @known_levels.index(severity) >= @known_levels.index(@active_level) Syslog.send(valid_levels[severity.to_sym], "#{from} #{msg}") end rescue Exception => e STDERR.puts("Failed to log: #{e.class}: #{e}: original log message: #{severity}: #{msg}") STDERR.puts(e.backtrace.join("\n\t")) end |
.method_missing(level, *args, &block) ⇒ Object
47 48 49 50 51 |
# File 'lib/typhon/log.rb', line 47 def method_missing(level, *args, &block) super unless [:info, :warn, :debug, :fatal, :error].include?(level) log(args[0], level) end |
.valid_levels ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/typhon/log.rb', line 39 def valid_levels {:info => :info, :warn => :warning, :debug => :debug, :fatal => :crit, :error => :err} end |