Class: Codesake::Commons::Logging
- Inherits:
-
Object
- Object
- Codesake::Commons::Logging
- Includes:
- Singleton
- Defined in:
- lib/codesake/commons/logging.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#silencer ⇒ Object
readonly
Returns the value of attribute silencer.
-
#syslog ⇒ Object
readonly
Returns the value of attribute syslog.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #die(msg, pid_file = nil) ⇒ Object
- #err(msg) ⇒ Object
- #helo(msg, pid_file = nil) ⇒ Object
-
#initialize ⇒ Logging
constructor
A new instance of Logging.
- #log(msg) ⇒ Object
- #ok(msg) ⇒ Object
- #toggle_silence ⇒ Object
- #toggle_syslog ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize ⇒ Logging
Returns a new instance of Logging.
15 16 17 18 19 20 21 |
# File 'lib/codesake/commons/logging.rb', line 15 def initialize super @silencer = false @verbose = true @syslog = true @filename = nil end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
13 14 15 |
# File 'lib/codesake/commons/logging.rb', line 13 def filename @filename end |
#silencer ⇒ Object (readonly)
Returns the value of attribute silencer.
10 11 12 |
# File 'lib/codesake/commons/logging.rb', line 10 def silencer @silencer end |
#syslog ⇒ Object (readonly)
Returns the value of attribute syslog.
12 13 14 |
# File 'lib/codesake/commons/logging.rb', line 12 def syslog @syslog end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
11 12 13 |
# File 'lib/codesake/commons/logging.rb', line 11 def verbose @verbose end |
Instance Method Details
#die(msg, pid_file = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/codesake/commons/logging.rb', line 23 def die(msg, pid_file=nil) STDERR.print "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(: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
31 32 33 34 35 |
# File 'lib/codesake/commons/logging.rb', line 31 def err(msg) STDERR.print "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:red) send_to_syslog(msg, :err) send_to_file(msg, :err) end |
#helo(msg, pid_file = nil) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/codesake/commons/logging.rb', line 56 def helo(msg, pid_file = nil) STDOUT.print "[*] #{msg} at #{Time.now.strftime("%H:%M:%S")}\n".color(:white) send_to_syslog(msg, :helo) send_to_file(msg, :helo) Codesake::Commons::Io.create_pid_file(pid_file) unless pid_file.nil? end |
#log(msg) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/codesake/commons/logging.rb', line 49 def log(msg) return if @silencer STDOUT.print "#{Time.now.strftime("%H:%M:%S")}: #{msg}\n".color(:white) send_to_syslog(msg, :debug) send_to_file(msg, :debug) end |
#ok(msg) ⇒ Object
43 44 45 46 47 |
# File 'lib/codesake/commons/logging.rb', line 43 def ok(msg) STDOUT.print "#{Time.now.strftime("%H:%M:%S")} [*] #{msg}\n".color(:green) send_to_syslog(msg, :log) send_to_file(msg, :log) end |
#toggle_silence ⇒ Object
63 64 65 66 |
# File 'lib/codesake/commons/logging.rb', line 63 def toggle_silence @silencer = ! @silencer @verbose = ! @silencer end |
#toggle_syslog ⇒ Object
68 69 70 71 72 |
# File 'lib/codesake/commons/logging.rb', line 68 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
37 38 39 40 41 |
# File 'lib/codesake/commons/logging.rb', line 37 def warn(msg) STDOUT.print "#{Time.now.strftime("%H:%M:%S")} [!] #{msg}\n".color(:yellow) send_to_syslog(msg, :warn) send_to_file(msg, :warn) end |