Module: BBFS::Log
- Defined in:
- lib/log.rb,
lib/log/version.rb,
lib/log/log_consumer.rb
Overview
Module: Log. Abstruct: The Log is used to log infowarningerrordebug messages Note: The logger will be automatically initialized if log_param_auto_start is true
If log_param_auto_start is false then 'Log.init' method will be called
on the first attempt to log.
Defined Under Namespace
Classes: BufferConsumerProducer, ConsoleConsumer, Consumer, FileConsumer
Constant Summary collapse
- VERSION =
"0.0.8"
Class Method Summary collapse
-
.add_consumer(consumer) ⇒ Object
Adding consumer to the logger.
-
.basic(msg, type) ⇒ Object
formatting the data and push to consumers.
-
.clear_consumers ⇒ Object
Clears consumers.
-
.debug1(msg) ⇒ Object
Log debug level 1 massages.
-
.debug2(msg) ⇒ Object
Log debug level 2 massages.
-
.debug3(msg) ⇒ Object
Log debug level 3 massages.
-
.error(msg) ⇒ Object
Log error massages.
-
.executable_name ⇒ Object
Auxiliary method to retrieve the executable name.
-
.info(msg) ⇒ Object
Log info massages.
-
.init ⇒ Object
Init the Log consumers.
-
.warning(msg) ⇒ Object
Log warning massages.
Class Method Details
.add_consumer(consumer) ⇒ Object
Adding consumer to the logger
81 82 83 |
# File 'lib/log.rb', line 81 def Log.add_consumer consumer @consumers.push consumer end |
.basic(msg, type) ⇒ Object
formatting the data and push to consumers
86 87 88 89 90 91 |
# File 'lib/log.rb', line 86 def Log.basic msg, type Log.init if not @log_initialized /([a-zA-Z0-9\-_\.]+:\d+)/ =~ caller[1] data = "[BBFS LOG] [#{Time.now()}] [#{type}] [#{$1}] [#{msg}]" @consumers.each { |consumer| consumer.push_data data } end |
.clear_consumers ⇒ Object
Clears consumers
76 77 78 |
# File 'lib/log.rb', line 76 def Log.clear_consumers @consumers.clear end |
.debug1(msg) ⇒ Object
Log debug level 1 massages
109 110 111 112 113 |
# File 'lib/log.rb', line 109 def Log.debug1 msg if Params['log_debug_level'] > 0 then Log.basic msg, 'DEBUG-1' end end |
.debug2(msg) ⇒ Object
Log debug level 2 massages
116 117 118 119 120 |
# File 'lib/log.rb', line 116 def Log.debug2 msg if Params['log_debug_level'] > 1 then Log.basic msg, 'DEBUG-2' end end |
.debug3(msg) ⇒ Object
Log debug level 3 massages
123 124 125 126 127 |
# File 'lib/log.rb', line 123 def Log.debug3 msg if Params['log_debug_level'] > 2 then Log.basic msg, 'DEBUG-3' end end |
.error(msg) ⇒ Object
Log error massages
99 100 101 |
# File 'lib/log.rb', line 99 def Log.error msg Log.basic msg, 'ERROR' end |
.executable_name ⇒ Object
Auxiliary method to retrieve the executable name
20 21 22 23 |
# File 'lib/log.rb', line 20 def Log.executable_name /([a-zA-Z0-9\-_\.]+):\d+/ =~ caller[caller.size-1] return $1 end |
.info(msg) ⇒ Object
Log info massages
104 105 106 |
# File 'lib/log.rb', line 104 def Log.info msg Log.basic msg, 'INFO' end |
.init ⇒ Object
Init the Log consumers
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/log.rb', line 51 def Log.init Log.clear_consumers # Console - If enabled, will flush the log immediately to the console if Params['log_write_to_console'] then console_consumer = ConsoleConsumer.new @consumers.push console_consumer end # BufferConsumerProducer - If enabled, will use the file consumer to flush a buffer to a file if Params['log_write_to_file'] then file_consumer = FileConsumer.new Params['log_file_name'] buffer_consumer_producer = BufferConsumerProducer.new \ Params['log_param_number_of_mega_bytes_stored_before_flush'], \ Params['log_param_max_elapsed_time_in_seconds_from_last_flush'] buffer_consumer_producer.add_consumer file_consumer @consumers.push buffer_consumer_producer end @log_initialized = true Log.info 'BBFS Log initialized.' # log first data Log.info "Log file path:'#{Params['log_file_name']}'" if Params['log_write_to_file'] Params.().each { |msg| Log.info msg } unless Params.().empty? end |