Class: Pakyow::Logger
- Inherits:
-
Object
- Object
- Pakyow::Logger
- Defined in:
- lib/pakyow/logger.rb,
lib/pakyow/logger/colorizer.rb,
lib/pakyow/logger/formatter.rb,
lib/pakyow/logger/timekeeper.rb,
lib/pakyow/logger/destination.rb,
lib/pakyow/logger/multiplexed.rb,
lib/pakyow/logger/thread_local.rb,
lib/pakyow/logger/formatters/json.rb,
lib/pakyow/logger/formatters/human.rb,
lib/pakyow/logger/formatters/logfmt.rb
Overview
Logs messages throughout the lifetime of an environment, connection, etc.
In addition to logging standard messages, this class provides a way to log a ‘prologue` and `epilogue` for a connection, as well as a `houston` method for logging errors.
Defined Under Namespace
Modules: Colorizer, Formatters, Timekeeper Classes: Destination, Formatter, Multiplexed, ThreadLocal
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<<(message) ⇒ Object
- #add(level, message = nil, &block) ⇒ Object (also: #log)
- #elapsed ⇒ Object
-
#epilogue(connection) ⇒ Object
Logs the conclusion of a request, including the response status.
-
#houston(error) ⇒ Object
Logs an error raised when processing the request.
-
#initialize(type, started_at: Time.now, id: SecureRandom.hex(4), output:, level:) ⇒ Logger
constructor
A new instance of Logger.
-
#prologue(connection) ⇒ Object
Logs the beginning of a request, including the time, request method, request uri, and originating ip address.
-
#silence(temporary_level = :error) ⇒ Object
Temporarily silences logs, up to
temporary_level
.
Constructor Details
#initialize(type, started_at: Time.now, id: SecureRandom.hex(4), output:, level:) ⇒ Logger
Returns a new instance of Logger.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pakyow/logger.rb', line 33 def initialize(type, started_at: Time.now, id: SecureRandom.hex(4), output:, level:) @type, @started_at, @id = type, started_at, id level = case level when :all 0 when :off 7 when Symbol self.class.const_get(:LEVELS)[level] else level end super(output, level: level) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
19 20 21 |
# File 'lib/pakyow/logger.rb', line 19 def id @id end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
23 24 25 |
# File 'lib/pakyow/logger.rb', line 23 def started_at @started_at end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/pakyow/logger.rb', line 27 def type @type end |
Instance Method Details
#<<(message) ⇒ Object
68 69 70 |
# File 'lib/pakyow/logger.rb', line 68 def <<() add(:unknown, ) end |
#add(level, message = nil, &block) ⇒ Object Also known as: log
72 73 74 |
# File 'lib/pakyow/logger.rb', line 72 def add(level, = nil, &block) public_send(level, , &block) end |
#elapsed ⇒ Object
102 103 104 |
# File 'lib/pakyow/logger.rb', line 102 def elapsed (Time.now - @started_at) end |
#epilogue(connection) ⇒ Object
Logs the conclusion of a request, including the response status.
90 91 92 |
# File 'lib/pakyow/logger.rb', line 90 def epilogue(connection) info { formatted_epilogue(connection) } end |
#houston(error) ⇒ Object
Logs an error raised when processing the request.
98 99 100 |
# File 'lib/pakyow/logger.rb', line 98 def houston(error) error { formatted_error(error) } end |
#prologue(connection) ⇒ Object
Logs the beginning of a request, including the time, request method, request uri, and originating ip address.
82 83 84 |
# File 'lib/pakyow/logger.rb', line 82 def prologue(connection) info { formatted_prologue(connection) } end |
#silence(temporary_level = :error) ⇒ Object
Temporarily silences logs, up to temporary_level
.
52 53 54 55 56 57 58 |
# File 'lib/pakyow/logger.rb', line 52 def silence(temporary_level = :error) original_level = @level self.level = self.class.const_get(:LEVELS)[temporary_level] yield ensure self.level = original_level end |