Class: Hanami::Config::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/config/logger.rb

Overview

Logger configuration

Since:

  • 0.8.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.

Since:

  • 0.8.0



11
12
13
# File 'lib/hanami/config/logger.rb', line 11

def initialize
  @stream = STDOUT
end

Instance Attribute Details

#application_moduleObject (readonly)

Since:

  • 0.8.0



9
10
11
# File 'lib/hanami/config/logger.rb', line 9

def application_module
  @application_module
end

Instance Method Details

#app_name(value) ⇒ Object #app_nameString

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.

Application name value.

Overloads:

  • #app_name(value) ⇒ Object

    Sets the given value

    Parameters:

    • value (String)

      for app name option

  • #app_nameString

    Gets the value

    Returns:

    • (String)

      app name option’s value

Since:

  • 0.8.0



135
136
137
138
139
140
141
# File 'lib/hanami/config/logger.rb', line 135

def app_name(value = nil)
  if value.nil?
    @app_name
  else
    @app_name = value
  end
end

#buildHanami::Logger, 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.

Returns new Hanami::Logger instance with all options

Returns:

  • (Hanami::Logger, Object)

    a logger

See Also:

Since:

  • 0.8.0



194
195
196
197
# File 'lib/hanami/config/logger.rb', line 194

def build
  @engine ||
    ::Hanami::Logger.new(@app_name, stream: @stream, level: @level, formatter: format)
end

#engine(value) ⇒ Object #engineObject

Custom logger engine.

This isn’t used by default, but allows developers to use their own logger.

Overloads:

  • #engine(value) ⇒ Object

    Sets the given value

    Parameters:

    • value (Object)

      a logger

  • #engineObject

    Gets the value

    Returns:

    • (Object)

      returns the logger

Since:

  • 0.8.0



54
55
56
57
58
59
60
# File 'lib/hanami/config/logger.rb', line 54

def engine(value = nil)
  if value.nil?
    @engine
  else
    @engine = value
  end
end

#format(value) ⇒ Object #formatString

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.

Logger format value.

Examples:

JSON format

require 'hanami/application'

module Bookshelf
  class Application < Hanami::Application
    configure do
      logger.format :json
    end
  end
end

custom format class

require 'hanami/application'

module Bookshelf
  class Application < Hanami::Application
    configure do
      logger.format MyCustomFormatter.new
    end
  end
end

Overloads:

  • #format(value) ⇒ Object

    Sets the given value

    Parameters:

    • value (String)

      for format option

  • #formatString

    Gets the value

    Returns:

    • (String)

      format option’s value

Since:

  • 0.8.0



177
178
179
180
181
182
183
# File 'lib/hanami/config/logger.rb', line 177

def format(value = nil)
  if value.nil?
    @format
  else
    @format = value
  end
end

#level(value) ⇒ Object #levelInteger, ...

Logger level

Available values are:

* DEBUG
* INFO
* WARN
* ERROR
* FATAL
* UNKNOWN

Examples:

Constant (Integer)

require 'hanami/application'

module Bookshelf
  class Application < Hanami::Application
    configure do
      logger.level Hanami::Logger::DEBUG
    end
  end
end

String

require 'hanami/application'

module Bookshelf
  class Application < Hanami::Application
    configure do
      logger.level 'debug'
    end
  end
end

Symbol

require 'hanami/application'

module Bookshelf
  class Application < Hanami::Application
    configure do
      logger.level :debug
    end
  end
end

Overloads:

  • #level(value) ⇒ Object

    Sets the given value

    Parameters:

    • value (Integer, String, Symbol)

      the logger level

  • #levelInteger, ...

    Gets the value

    Returns:

    • (Integer, String, Symbol)

      returns the level

Since:

  • 0.8.0



115
116
117
118
119
120
121
# File 'lib/hanami/config/logger.rb', line 115

def level(value = nil)
  if value.nil?
    @level
  else
    @level = value
  end
end

#stream(value) ⇒ Object #streamString, ...

Log stream.

STDOUT by default.

It accepts relative or absolute paths expressed as String, or Pathname.

It can also accept a IO or StringIO as output stream.

Overloads:

  • #stream(value) ⇒ Object

    Sets the given value

    Parameters:

    • value (String, Pathname, IO, StringIO)

      for log stream option.

  • #streamString, ...

    Gets the value

    Returns:

    • (String, Pathname, IO, StringIO)

      log stream option’s value

Since:

  • 0.8.0



33
34
35
36
37
38
39
# File 'lib/hanami/config/logger.rb', line 33

def stream(value = nil)
  if value.nil?
    @stream
  else
    @stream = value
  end
end