Module: IONeLoggerKit
- Defined in:
- service/log.rb
Overview
IONe built-in logger functions
Constant Summary collapse
- DESTINATIONS =
Table with log locations linked to method name or given label
Hash.new('ione.log')
Instance Method Summary collapse
-
#id_gen ⇒ String
ID generator.
-
#LOG(msg, method = "none", time = true) ⇒ Boolean
Logging the message to the one of three destinations.
-
#LOG_AUTO(msg, method = caller_locations(1, 1)[0].label, time = true) ⇒ Boolean
Logging the message to the one of three destinations.
-
#LOG_COLOR(msg, method = caller_locations(1, 1)[0].label.dup, color = 'red', font = 'bold') ⇒ Object
(also: #LOG_ERROR)
Logging the message with choosen color and font to the one of two destinations Check out 'colorize' gem for available colors and fonts.
-
#LOG_DEBUG(msg, _method = 'DEBUG', _time = true) ⇒ Object
Logging the message directly into LOG_LOCATION/debug.log.
Instance Method Details
#id_gen ⇒ String
ID generator
112 113 114 |
# File 'service/log.rb', line 112 def id_gen ($id += 1).to_s(16) end |
#LOG(msg, method = "none", time = true) ⇒ Boolean
If method name setted to 'SnapController', message will be logged into snapshot.log
If method name setted to 'DEBUG', message will be logged into debug.log
Logging the message to the one of three destinations
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'service/log.rb', line 27 def LOG(msg, method = "none", time = true) case method when 'DEBUG' destination = "#{LOG_ROOT}/debug.log" when "SnapController" destination = "#{LOG_ROOT}/snapshot.log" when "TrafficRecorder" destination = "#{LOG_ROOT}/traffic_recorder.log" else destination = "#{LOG_ROOT}/ione.log" end msg = msg.to_s msg = "[ #{Time.now.ctime} ] " + msg if time msg += " [ #{method} ]" if method != 'none' && method != "" && method != nil File.open(destination, 'a') { |log| log.write msg + "\n" } File.open("#{LOG_ROOT}/suspend.log", 'a') { |log| log.write msg + "\n" } if method == 'Suspend' $log << "#{msg} | #{destination}" true end |
#LOG_AUTO(msg, method = caller_locations(1, 1)[0].label, time = true) ⇒ Boolean
This function gets method name automatically
If method name setted to 'SnapController', message will be logged into snapshot.log
If method name setted to 'DEBUG', message will be logged into debug.log
Logging the message to the one of three destinations
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'service/log.rb', line 85 def LOG_AUTO(msg, method = caller_locations(1, 1)[0].label, time = true) case method when 'DEBUG' destination = "#{LOG_ROOT}/debug.log" when "SnapController" destination = "#{LOG_ROOT}/snapshot.log" when "TrafficRecorder" destination = "#{LOG_ROOT}/traffic_recorder.log" else destination = "#{LOG_ROOT}/ione.log" end msg = msg.to_s msg = "[ #{Time.now.ctime} ] " + msg if time msg += " [ #{method} ]" if method != 'none' && method != "" && method != nil File.open(destination, 'a') { |log| log.write msg + "\n" } File.open("#{LOG_ROOT}/suspend.log", 'a') { |log| log.write msg + "\n" } if method == 'Suspend' $log << "#{msg} | #{destination}" true end |
#LOG_COLOR(msg, method = caller_locations(1, 1)[0].label.dup, color = 'red', font = 'bold') ⇒ Object Also known as: LOG_ERROR
Logging the message with choosen color and font to the one of two destinations Check out 'colorize' gem for available colors and fonts
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'service/log.rb', line 51 def LOG_COLOR(msg, method = caller_locations(1, 1)[0].label.dup, color = 'red', font = 'bold') destination = "#{LOG_ROOT}/ione.log" destination = "#{LOG_ROOT}/snapshot.log" if method == "SnapController" destination = "#{LOG_ROOT}/traffic_recorder.log" if method == "TrafficRecorder" msg = msg.to_s.send(color).send(font) msg = "[ #{Time.now.ctime} ] " + msg method.slice!('block in '.dup) msg += " [ #{method} ]" if method != 'none' && method != "" && method != nil File.open(destination, 'a') { |log| log.write msg + "\n" } File.open("#{LOG_ROOT}/suspend.log", 'a') { |log| log.write msg + "\n" } if method == 'Suspend' $log << "#{msg} | #{destination}" true end |
#LOG_DEBUG(msg, _method = 'DEBUG', _time = true) ⇒ Object
Logging the message directly into LOG_LOCATION/debug.log
69 70 71 72 73 74 75 |
# File 'service/log.rb', line 69 def LOG_DEBUG(msg, _method = 'DEBUG', _time = true) destination = "#{LOG_ROOT}/debug.log" msg = "[ #{Time.now.ctime} ] #{msg}" File.open(destination, 'a') { |log| log.write msg + "\n" } $log << "#{msg} | #{destination}" true end |