Class: StructuredLogger
- Inherits:
-
Object
- Object
- StructuredLogger
- Extended by:
- Forwardable
- Includes:
- Logger::Severity
- Defined in:
- lib/structured_logger.rb,
lib/structured_logger/version.rb
Defined Under Namespace
Classes: Formatter
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Class Method Summary collapse
Instance Method Summary collapse
- #add(severity, *args, &block) ⇒ Object
- #debug(*args, &block) ⇒ Object
- #error(*args, &block) ⇒ Object
- #fatal(*args, &block) ⇒ Object
- #info(*args, &block) ⇒ Object
-
#initialize(io) ⇒ StructuredLogger
constructor
A new instance of StructuredLogger.
- #warn(*args, &block) ⇒ Object
Constructor Details
#initialize(io) ⇒ StructuredLogger
Returns a new instance of StructuredLogger.
15 16 17 18 19 |
# File 'lib/structured_logger.rb', line 15 def initialize(io) @logger = Logger.new(io) @formatter = nil @default_formatter = Formatter.new end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
9 10 11 |
# File 'lib/structured_logger.rb', line 9 def formatter @formatter end |
Class Method Details
.severity_name(severity) ⇒ Object
11 12 13 |
# File 'lib/structured_logger.rb', line 11 def self.severity_name(severity) return Logger::SEV_LABEL[severity] || "ANY" end |
Instance Method Details
#add(severity, *args, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/structured_logger.rb', line 48 def add(severity, *args, &block) if level > severity return end if block_given? *args = yield end s = (@formatter || @default_formatter).call(severity, Time.now, *args) @logger << s end |
#debug(*args, &block) ⇒ Object
28 29 30 |
# File 'lib/structured_logger.rb', line 28 def debug(*args, &block) add(DEBUG, *args, &block) end |
#error(*args, &block) ⇒ Object
40 41 42 |
# File 'lib/structured_logger.rb', line 40 def error(*args, &block) add(ERROR, *args, &block) end |
#fatal(*args, &block) ⇒ Object
44 45 46 |
# File 'lib/structured_logger.rb', line 44 def fatal(*args, &block) add(FATAL, *args, &block) end |
#info(*args, &block) ⇒ Object
32 33 34 |
# File 'lib/structured_logger.rb', line 32 def info(*args, &block) add(INFO, *args, &block) end |
#warn(*args, &block) ⇒ Object
36 37 38 |
# File 'lib/structured_logger.rb', line 36 def warn(*args, &block) add(WARN, *args, &block) end |