Class: Facter::Log
- Inherits:
-
Object
- Object
- Facter::Log
- Defined in:
- lib/framework/logging/logger.rb
Constant Summary collapse
- @@logger =
nil
- @@message_callback =
nil
- @@has_errors =
false
Class Method Summary collapse
- .errors? ⇒ Boolean
- .level ⇒ Object
- .level=(log_level) ⇒ Object
- .on_message(&block) ⇒ Object
- .output(output) ⇒ Object
- .set_logger_format ⇒ Object
Instance Method Summary collapse
- #debug(msg) ⇒ Object
- #error(msg, colorize = false) ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(logged_class) ⇒ Log
constructor
A new instance of Log.
- #warn(msg) ⇒ Object
Constructor Details
#initialize(logged_class) ⇒ Log
Returns a new instance of Log.
51 52 53 54 55 56 57 |
# File 'lib/framework/logging/logger.rb', line 51 def initialize(logged_class) @class_name = LoggerHelper.determine_callers_name(logged_class) return unless @@logger.nil? @@logger = Logger.new(STDOUT) @@logger.level = DEFAULT_LOG_LEVEL end |
Class Method Details
.errors? ⇒ Boolean
31 32 33 |
# File 'lib/framework/logging/logger.rb', line 31 def errors? @@has_errors end |
.level ⇒ Object
27 28 29 |
# File 'lib/framework/logging/logger.rb', line 27 def level @@logger.level end |
.level=(log_level) ⇒ Object
23 24 25 |
# File 'lib/framework/logging/logger.rb', line 23 def level=(log_level) @@logger.level = log_level end |
.on_message(&block) ⇒ Object
19 20 21 |
# File 'lib/framework/logging/logger.rb', line 19 def (&block) @@message_callback = block end |
.output(output) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/framework/logging/logger.rb', line 35 def output(output) return if @@logger @@logger = Logger.new(output) set_logger_format @@logger.level = DEFAULT_LOG_LEVEL end |
.set_logger_format ⇒ Object
43 44 45 46 47 48 |
# File 'lib/framework/logging/logger.rb', line 43 def set_logger_format @@logger.formatter = proc do |severity, datetime, _progname, msg| datetime = datetime.strftime(@datetime_format || '%Y-%m-%d %H:%M:%S.%6N ') "[#{datetime}] #{severity} #{msg} \n" end end |
Instance Method Details
#debug(msg) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/framework/logging/logger.rb', line 59 def debug(msg) return unless debugging_active? if msg.nil? || msg.empty? (msg) elsif @@message_callback @@message_callback.call(:debug, msg) else msg = colorize(msg, CYAN) if Options[:color] @@logger.debug(@class_name + ' - ' + msg) end end |
#error(msg, colorize = false) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/framework/logging/logger.rb', line 94 def error(msg, colorize = false) @@has_errors = true if msg.nil? || msg.empty? (msg) elsif @@message_callback @@message_callback.call(:error, msg) else msg = colorize(msg, RED) if colorize || Options[:color] @@logger.error(@class_name + ' - ' + msg) end end |
#info(msg) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/framework/logging/logger.rb', line 72 def info(msg) if msg.nil? || msg.empty? (msg) elsif @@message_callback @@message_callback.call(:info, msg) else msg = colorize(msg, GREEN) if Options[:color] @@logger.info(@class_name + ' - ' + msg) end end |
#warn(msg) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/framework/logging/logger.rb', line 83 def warn(msg) if msg.nil? || msg.empty? (msg) elsif @@message_callback @@message_callback.call(:warn, msg) else msg = colorize(msg, YELLOW) if Options[:color] @@logger.warn(@class_name + ' - ' + msg) end end |