Class: Hanami::Web::RackLogger::UniversalLogger Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/web/rack_logger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ UniversalLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of UniversalLogger.

Since:

  • 2.1.0



92
93
94
# File 'lib/hanami/web/rack_logger.rb', line 92

def initialize(logger)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



88
89
90
# File 'lib/hanami/web/rack_logger.rb', line 88

def logger
  @logger
end

Class Method Details

.call(logger) ⇒ Object Also known as: []

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



65
66
67
68
69
# File 'lib/hanami/web/rack_logger.rb', line 65

def call(logger)
  return logger if compatible_logger?(logger)

  new(logger)
end

Instance Method Details

#error(message = nil, **payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Also:

Since:

  • 2.1.0



118
119
120
121
# File 'lib/hanami/web/rack_logger.rb', line 118

def error(message = nil, **payload)
  payload[:message] = message if message
  logger.info(JSON.fast_generate(payload))
end

#info(message = nil, **payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Logs the entry as JSON.

This ensures a reasonable (and parseable) representation of our log payload structures for loggers that are configured to wholly replace Hanami’s default logger.

Since:

  • 2.1.0



109
110
111
112
# File 'lib/hanami/web/rack_logger.rb', line 109

def info(message = nil, **payload)
  payload[:message] = message if message
  logger.info(JSON.fast_generate(payload))
end

#tagged(&blk) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



98
99
100
# File 'lib/hanami/web/rack_logger.rb', line 98

def tagged(*, &blk)
  blk.call
end