Class: Palmade::Tapsilog::Logger

Inherits:
Client
  • Object
show all
Defined in:
lib/palmade/tapsilog/logger.rb

Constant Summary collapse

LOG_LEVEL_TEXT =
[ 'debug', 'info', 'warn', 'error', 'fatal', 'unknown' ]

Constants inherited from Client

Client::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#close, #closed?, #flush, #reconnect

Constructor Details

#initialize(*args, &block) ⇒ Logger

Returns a new instance of Logger.



9
10
11
12
# File 'lib/palmade/tapsilog/logger.rb', line 9

def initialize(*args, &block)
  super(*args, &block)
  @level = INFO
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

Instance Method Details

#add(severity, message = nil, progname = nil, tags = {}, &block) ⇒ Object Also known as: log



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/palmade/tapsilog/logger.rb', line 54

def add(severity, message = nil, progname = nil, tags = {}, &block)
  case severity
  when 'authentication'
    return log_without_rails_extensions(severity, message)
  when String, Symbol
    severity = LOG_LEVEL_TEXT.index(severity.to_s.downcase) || UNKNOWN
  when nil
    severity = UNKNOWN
  end

  if severity < @level
    return true
  end

  log_level_text = LOG_LEVEL_TEXT[severity]
  progname ||= @service
  message = if message.nil?
    if block_given?
      message = yield
    else
      progname
    end
  else
    message.to_s
  end

  log_without_rails_extensions(log_level_text, message, tags)
end

#debug(progname = nil, tags = {}, &block) ⇒ Object



26
27
28
# File 'lib/palmade/tapsilog/logger.rb', line 26

def debug(progname = nil, tags = {}, &block)
  add(DEBUG, nil, progname, tags, &block)
end

#debug?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/palmade/tapsilog/logger.rb', line 22

def debug?
  @level <= DEBUG
end

#error(progname = nil, tags = {}, &block) ⇒ Object



34
35
36
# File 'lib/palmade/tapsilog/logger.rb', line 34

def error(progname = nil, tags = {}, &block)
  add(ERROR, nil, progname, tags, &block)
end

#error?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/palmade/tapsilog/logger.rb', line 30

def error?
  @level <= ERROR
end

#fatal(progname = nil, tags = {}, &block) ⇒ Object



42
43
44
# File 'lib/palmade/tapsilog/logger.rb', line 42

def fatal(progname = nil, tags = {}, &block)
  add(FATAL, nil, progname, tags, &block)
end

#fatal?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/palmade/tapsilog/logger.rb', line 38

def fatal?
  @level <= FATAL
end

#info(progname = nil, tags = {}, &block) ⇒ Object



18
19
20
# File 'lib/palmade/tapsilog/logger.rb', line 18

def info(progname = nil, tags = {}, &block)
  add(INFO, nil, progname, tags, &block)
end

#info?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/palmade/tapsilog/logger.rb', line 14

def info?
  @level <= INFO
end

#warn(progname = nil, tags = {}, &block) ⇒ Object



50
51
52
# File 'lib/palmade/tapsilog/logger.rb', line 50

def warn(progname = nil, tags = {}, &block)
  add(WARN, nil, progname, tags, &block)
end

#warn?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/palmade/tapsilog/logger.rb', line 46

def warn?
  @level <= WARN
end