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, &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.

See Also:

Since:

  • 2.1.0



124
125
126
127
128
129
130
131
132
133
# File 'lib/hanami/web/rack_logger.rb', line 124

def error(message = nil, **payload, &blk)
  logger.error do
    if blk
      JSON.generate(blk.call)
    else
      payload[:message] = message if message
      JSON.generate(payload)
    end
  end
end

#info(message = nil, **payload, &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.

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
113
114
115
116
117
118
# File 'lib/hanami/web/rack_logger.rb', line 109

def info(message = nil, **payload, &blk)
  logger.info do
    if blk
      JSON.generate(blk.call)
    else
      payload[:message] = message if message
      JSON.generate(payload)
    end
  end
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