Class: Zakuro::Output::Logger

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

Overview

Note:

本番では使用しない

軽量なロガー

Constant Summary collapse

LEVELS =

Returns ログレベル.

Returns:

  • (Hash<Symbol, Integer>)

    ログレベル

{
  none: -1,
  debug: 0,
  info: 1,
  warn: 2,
  error: 3
}.freeze
LEVEL =

Returns 現在ログレベル.

Returns:

  • (Integer)

    現在ログレベル

LEVELS[:none]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:) ⇒ Logger

Returns a new instance of Logger.



27
28
29
# File 'lib/zakuro/output/logger.rb', line 27

def initialize(location:)
  @location = location
end

Instance Attribute Details

#locationString (readonly)

Returns 呼び出し位置.

Returns:

  • (String)

    呼び出し位置



25
26
27
# File 'lib/zakuro/output/logger.rb', line 25

def location
  @location
end

Instance Method Details

#debug(*messages) ⇒ Object

DEBUGレベルの標準出力を行う

Parameters:

  • messages (String)

    メッセージ



36
37
38
39
40
41
42
# File 'lib/zakuro/output/logger.rb', line 36

def debug(*messages)
  return if none?

  return if LEVELS[:debug] < LEVEL

  output('DEBUG', *messages)
end

#error(error, *messages) ⇒ Object

ERRORレベルの標準出力を行う

Parameters:

  • error (Error)

    例外

  • messages (String)

    メッセージ



63
64
65
66
67
68
69
70
71
# File 'lib/zakuro/output/logger.rb', line 63

def error(error, *messages)
  return if none?

  return if LEVELS[:error] < LEVEL

  output('ERROR', *messages)
  output('ERROR', error.message)
  output('ERROR', *error.backtrace)
end

#info(*messages) ⇒ Object

INFOレベルの標準出力を行う

Parameters:

  • messages (String)

    メッセージ



49
50
51
52
53
54
55
# File 'lib/zakuro/output/logger.rb', line 49

def info(*messages)
  return if none?

  return if LEVELS[:info] < LEVEL

  output('INFO', *messages)
end