Class: Contr::Logger::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/contr/logger/default.rb

Constant Summary collapse

DEFAULT_STREAM =
$stdout
DEFAULT_LOG_LEVEL =
:debug
DEFAULT_TAG =
"contract-failed"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream: DEFAULT_STREAM, log_level: DEFAULT_LOG_LEVEL, tag: DEFAULT_TAG) ⇒ Default

Returns a new instance of Default.



15
16
17
18
19
20
# File 'lib/contr/logger/default.rb', line 15

def initialize(stream: DEFAULT_STREAM, log_level: DEFAULT_LOG_LEVEL, tag: DEFAULT_TAG)
  @stream = stream
  @stream_logger = ::Logger.new(stream)
  @log_level = log_level
  @tag = tag
end

Instance Attribute Details

#log_levelObject (readonly)

Returns the value of attribute log_level.



13
14
15
# File 'lib/contr/logger/default.rb', line 13

def log_level
  @log_level
end

#streamObject (readonly)

Returns the value of attribute stream.



13
14
15
# File 'lib/contr/logger/default.rb', line 13

def stream
  @stream
end

#stream_loggerObject (readonly)

Returns the value of attribute stream_logger.



13
14
15
# File 'lib/contr/logger/default.rb', line 13

def stream_logger
  @stream_logger
end

#tagObject (readonly)

Returns the value of attribute tag.



13
14
15
# File 'lib/contr/logger/default.rb', line 13

def tag
  @tag
end

Instance Method Details

#log(state) ⇒ Object



22
23
24
25
26
# File 'lib/contr/logger/default.rb', line 22

def log(state)
  message = state.merge(tag: tag).to_json

  stream_logger.send(log_level, message)
end