Class: Loggem::Logger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger = ::Logger.new(STDOUT)) ⇒ Logger

Returns a new instance of Logger.



11
12
13
14
15
# File 'lib/loggem/logger.rb', line 11

def initialize(logger = ::Logger.new(STDOUT))
  @logger = logger
  @context = {}
  @formatter = ::Loggem::Formatters::Json.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments) ⇒ Object



39
40
41
# File 'lib/loggem/logger.rb', line 39

def method_missing(method, *arguments)
  logger.public_send method, *arguments
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/loggem/logger.rb', line 7

def context
  @context
end

#formatter=(formatter) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
# File 'lib/loggem/logger.rb', line 19

def formatter=(formatter)
  raise ArgumentError.new("Formatter must respond to 'call'") unless formatter.respond_to?(:call)

  @formatter = formatter
end