Class: DailyLogger
- Inherits:
-
Object
- Object
- DailyLogger
- Includes:
- Severity
- Defined in:
- lib/daily_logger.rb,
lib/daily_logger/adapter.rb,
lib/daily_logger/formatter.rb,
lib/daily_logger/adapter/file.rb
Defined Under Namespace
Modules: Severity Classes: Adapter, Formatter
Constant Summary
Constants included from Severity
Severity::DEBUG, Severity::ERROR, Severity::FATAL, Severity::INFO, Severity::UNKNOWN, Severity::WARN
Instance Attribute Summary collapse
-
#device ⇒ Object
Returns the value of attribute device.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#level ⇒ Object
(also: #sev_threshold)
Logging severity threshold (e.g.
Logger::INFO).
Instance Method Summary collapse
- #append(severity, msg = nil, &block) ⇒ Object (also: #log)
- #close ⇒ Object
- #debug(*msg, &block) ⇒ Object
-
#debug? ⇒ Boolean
Returns
trueiff the current severity level allows for the printing ofDEBUGmessages. - #error(*msg, &block) ⇒ Object
-
#error? ⇒ Boolean
Returns
trueiff the current severity level allows for the printing ofERRORmessages. - #fatal(*msg, &block) ⇒ Object
-
#fatal? ⇒ Boolean
Returns
trueiff the current severity level allows for the printing ofFATALmessages. - #info(*msg, &block) ⇒ Object
-
#info? ⇒ Boolean
Returns
trueiff the current severity level allows for the printing ofINFOmessages. -
#initialize(name = nil) ⇒ DailyLogger
constructor
A new instance of DailyLogger.
- #unknown(*msg, &block) ⇒ Object
- #warn(*msg, &block) ⇒ Object
-
#warn? ⇒ Boolean
Returns
trueiff the current severity level allows for the printing ofWARNmessages.
Constructor Details
#initialize(name = nil) ⇒ DailyLogger
Returns a new instance of DailyLogger.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/daily_logger.rb', line 32 def initialize(name = nil) @name = name || 'all' @level = DEBUG @default_formatter = DailyLogger::Formatter.new @formatter = nil @log_adaptor = {} sev_label.each do |level| @log_adaptor[level] = DailyLogger::Adapter.new(level, @name) end end |
Instance Attribute Details
#device ⇒ Object
Returns the value of attribute device.
30 31 32 |
# File 'lib/daily_logger.rb', line 30 def device @device end |
#formatter ⇒ Object
Returns the value of attribute formatter.
29 30 31 |
# File 'lib/daily_logger.rb', line 29 def formatter @formatter end |
#level ⇒ Object Also known as: sev_threshold
Logging severity threshold (e.g. Logger::INFO).
25 26 27 |
# File 'lib/daily_logger.rb', line 25 def level @level end |
Instance Method Details
#append(severity, msg = nil, &block) ⇒ Object Also known as: log
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/daily_logger.rb', line 44 def append(severity, msg = nil, &block) severity ||= UNKNOWN if @log_adaptor.nil? or severity < @level return true end block_msg = nil if block_given? block_msg = yield end log_level = sev_label[severity] if @log_adaptor[log_level].nil? @log_adaptor[log_level] = DailyLogger::Adapter.new(log_level, @name) end @log_adaptor[log_level].write(log_level, (Time.now, msg, block_msg)) true end |
#close ⇒ Object
113 114 115 116 117 118 |
# File 'lib/daily_logger.rb', line 113 def close sev_label.each do |level| next if @log_adaptor[level].nil? @log_adaptor[level].close end end |
#debug(*msg, &block) ⇒ Object
66 67 68 |
# File 'lib/daily_logger.rb', line 66 def debug(*msg, &block) append(DEBUG, msg, &block) end |
#debug? ⇒ Boolean
Returns true iff the current severity level allows for the printing of DEBUG messages.
95 |
# File 'lib/daily_logger.rb', line 95 def debug?; @level <= DEBUG; end |
#error(*msg, &block) ⇒ Object
79 80 81 82 |
# File 'lib/daily_logger.rb', line 79 def error(*msg, &block) #msg = called_from.concat msg append(ERROR, msg, &block) end |
#error? ⇒ Boolean
Returns true iff the current severity level allows for the printing of ERROR messages.
107 |
# File 'lib/daily_logger.rb', line 107 def error?; @level <= ERROR; end |
#fatal(*msg, &block) ⇒ Object
84 85 86 87 |
# File 'lib/daily_logger.rb', line 84 def fatal(*msg, &block) #msg = called_from.concat msg append(FATAL, msg, &block) end |
#fatal? ⇒ Boolean
Returns true iff the current severity level allows for the printing of FATAL messages.
111 |
# File 'lib/daily_logger.rb', line 111 def fatal?; @level <= FATAL; end |
#info(*msg, &block) ⇒ Object
70 71 72 |
# File 'lib/daily_logger.rb', line 70 def info(*msg, &block) append(INFO, msg, &block) end |
#info? ⇒ Boolean
Returns true iff the current severity level allows for the printing of INFO messages.
99 |
# File 'lib/daily_logger.rb', line 99 def info?; @level <= INFO; end |
#unknown(*msg, &block) ⇒ Object
89 90 91 |
# File 'lib/daily_logger.rb', line 89 def unknown(*msg, &block) append(UNKNOWN, msg, &block) end |
#warn(*msg, &block) ⇒ Object
74 75 76 77 |
# File 'lib/daily_logger.rb', line 74 def warn(*msg, &block) #msg = called_from.concat msg append(WARN, msg, &block) end |
#warn? ⇒ Boolean
Returns true iff the current severity level allows for the printing of WARN messages.
103 |
# File 'lib/daily_logger.rb', line 103 def warn?; @level <= WARN; end |