Class: Codesake::Commons::Logging
- Inherits:
-
Object
- Object
- Codesake::Commons::Logging
- Includes:
- Singleton
- Defined in:
- lib/codesake/commons/logging.rb
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#debug(msg) ⇒ Object
Returns the value of attribute debug.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#silence ⇒ Object
Returns the value of attribute silence.
-
#syslog ⇒ Object
Returns the value of attribute syslog.
Instance Method Summary collapse
- #bug(msg) ⇒ Object
- #bye(pid_file = nil) ⇒ Object
- #die(msg, pid_file = nil) ⇒ Object
- #err(msg) ⇒ Object
- #helo(component, version, pid_file = nil) ⇒ Object
-
#initialize ⇒ Logging
constructor
A new instance of Logging.
- #log(msg) ⇒ Object
- #ok(msg) ⇒ Object
- #toggle_syslog ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize ⇒ Logging
Returns a new instance of Logging.
16 17 18 19 20 21 22 23 |
# File 'lib/codesake/commons/logging.rb', line 16 def initialize super @silence = false @debug = true @syslog = false @filename = nil @component = "" end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
14 15 16 |
# File 'lib/codesake/commons/logging.rb', line 14 def component @component end |
#debug(msg) ⇒ Object
Returns the value of attribute debug.
11 12 13 |
# File 'lib/codesake/commons/logging.rb', line 11 def debug @debug end |
#filename ⇒ Object
Returns the value of attribute filename.
13 14 15 |
# File 'lib/codesake/commons/logging.rb', line 13 def filename @filename end |
#silence ⇒ Object
Returns the value of attribute silence.
10 11 12 |
# File 'lib/codesake/commons/logging.rb', line 10 def silence @silence end |
#syslog ⇒ Object
Returns the value of attribute syslog.
12 13 14 |
# File 'lib/codesake/commons/logging.rb', line 12 def syslog @syslog end |
Instance Method Details
#bug(msg) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/codesake/commons/logging.rb', line 83 def bug(msg) return if @silence STDERR.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [%] #{@component}: - BUG - #{msg}\n").red.bright send_to_syslog(msg, :debug) send_to_file(msg, :debug) end |
#bye(pid_file = nil) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/codesake/commons/logging.rb', line 68 def bye(pid_file = nil) STDOUT.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [*] #{@component} is leaving\n").white send_to_syslog("#{@component} is leaving", :helo) send_to_file("#{@component} is leaving", :helo) Codesake::Commons::Io.remove_pid_file(pid_file) unless pid_file.nil? end |
#die(msg, pid_file = nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/codesake/commons/logging.rb', line 25 def die(msg, pid_file=nil) STDERR.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [!] #{@component}: #{msg}\n").red send_to_syslog(msg, :helo) send_to_file(msg, :helo) Codesake::Commons::Io.remove_pid_file(pid_file) unless pid_file.nil? Kernel.exit(-1) end |
#err(msg) ⇒ Object
33 34 35 36 37 |
# File 'lib/codesake/commons/logging.rb', line 33 def err(msg) STDERR.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [!] #{@component}: #{msg}\n").red send_to_syslog(msg, :err) send_to_file(msg, :err) end |
#helo(component, version, pid_file = nil) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/codesake/commons/logging.rb', line 60 def helo(component, version, pid_file = nil) @component = component STDOUT.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [*] #{@component} v#{version} is starting up\n").white send_to_syslog("#{@component} v#{version} is starting up", :helo) send_to_file("#{@component} v#{version} is starting up", :helo) Codesake::Commons::Io.create_pid_file(pid_file) unless pid_file.nil? end |
#log(msg) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/codesake/commons/logging.rb', line 53 def log(msg) return if @silence STDOUT.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [$] #{@component}: #{msg}\n").white send_to_syslog(msg, :log) send_to_file(msg, :log) end |
#ok(msg) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/codesake/commons/logging.rb', line 46 def ok(msg) return if @silence STDOUT.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [*] #{@component}: #{msg}\n").green send_to_syslog(msg, :log) send_to_file(msg, :log) end |
#toggle_syslog ⇒ Object
90 91 92 93 94 |
# File 'lib/codesake/commons/logging.rb', line 90 def toggle_syslog @syslog = ! @syslog warn("codesake messages to syslog are now disabled") unless @syslog ok("codesake messages to syslog are now enabled") if @syslog end |
#warn(msg) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/codesake/commons/logging.rb', line 39 def warn(msg) return if @silence STDOUT.print Rainbow("#{Time.now.strftime("%H:%M:%S")} [w] #{@component}: #{msg}\n").yellow send_to_syslog(msg, :warn) send_to_file(msg, :warn) end |