Class: ReeLogger::MultiLogger

Inherits:
Logger
  • Object
show all
Includes:
Ree::LinkDSL
Defined in:
lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb

Constant Summary collapse

LEVEL_MAPPING =
{
  debug: Logger::DEBUG,
  info: Logger::INFO,
  warn: Logger::WARN,
  error: Logger::ERROR,
  fatal: Logger::FATAL,
  unknown: Logger::UNKNOWN
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Logger

#build

Constructor Details

#initialize(progname, rate_limiter, filter_words) ⇒ MultiLogger

Returns a new instance of MultiLogger.



30
31
32
33
34
35
36
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 30

def initialize(progname, rate_limiter, filter_words)
  @progname = progname
  @rate_limiter = rate_limiter
  @filter_words = filter_words || []
  @appenders = []
  @silenced  = false
end

Instance Attribute Details

#appendersObject (readonly)

Returns the value of attribute appenders.



23
24
25
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 23

def appenders
  @appenders
end

#prognameObject (readonly)

Returns the value of attribute progname.



23
24
25
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 23

def progname
  @progname
end

#silencedObject (readonly)

Returns the value of attribute silenced.



23
24
25
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 23

def silenced
  @silenced
end

Instance Method Details

#add_appender(appender) ⇒ Object



38
39
40
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 38

def add_appender(appender)
  @appenders.push(appender)
end

#debug(message = nil, parameters = {}, exception = nil, log_args = false, progname = nil, &block) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 61

def debug(message = nil, parameters = {}, exception = nil, log_args = false, progname = nil, &block)
  if block_given?
    log_block(:debug, parameters, log_args, yield)
  else
    msg = get_message(message)
    log(:debug, msg, parameters, nil, log_args)
  end
end

#error(message = nil, parameters = {}, exception = nil, log_args = true, progname = nil, &block) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 91

def error(message = nil, parameters = {}, exception = nil, log_args = true, progname = nil,  &block)
  if block_given?
    log_block(:error, parameters, log_args, yield)
  else
    msg = get_message(message)
    log(:error, msg, parameters, exception, log_args)
  end
end

#fatal(message = nil, parameters = {}, exception = nil, log_args = true, progname = nil, &block) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 101

def fatal(message = nil, parameters = {}, exception = nil, log_args = true, progname = nil, &block)
  if block_given?
    log_block(:fatal, parameters, log_args, yield)
  else
    msg = get_message(message)
    log(:fatal, msg, parameters, exception, log_args)
  end
end

#info(message = nil, parameters = {}, exception = nil, log_args = false, progname = nil, &block) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 71

def info(message = nil, parameters = {}, exception = nil, log_args = false, progname = nil, &block)
  if block_given?
    log_block(:info, parameters, log_args, yield)
  else
    msg = get_message(message)
    log(:info, msg, parameters, nil)
  end
end

#log(level, message, parameters = {}, exception = nil, log_args = false) ⇒ Object Also known as: add



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 130

def log(level, message, parameters = {}, exception = nil, log_args = false)
  if @rate_limiter
    @rate_limiter.call do
      log_event(level, message, parameters, exception, log_args)
    end
  else
    log_event(level, message, parameters, exception, log_args)
  end

  nil
end

#log_block(error, parameters, log_args, block_parameters) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 121

def log_block(error, parameters, log_args, block_parameters)
  if block_parameters.is_a?(Hash)
    log(error, "", block_parameters.merge(parameters), nil, log_args)
  else
    log(error, block_parameters, parameters, nil, log_args)
  end
end

#silence(&block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 43

def silence(&block)
  if block_given?
    @silenced = true
    block.call
    unsilence
  else
    @silenced = true
  end

  @silenced
end

#unknown(message = nil, parameters = {}, exception = nil, log_args = true, progname = nil, &block) ⇒ Object



111
112
113
114
115
116
117
118
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 111

def unknown(message = nil, parameters = {}, exception = nil, log_args = true, progname = nil,  &block)
  if block_given?
    log_block(:unknown, parameters, log_args, yield)
  else
    msg = get_message(message)
    log(:unknown, msg, parameters, exception, log_args)
  end
end

#unsilenceObject



56
57
58
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 56

def unsilence
  @silenced = false
end

#warn(message = nil, parameters = {}, exception = nil, log_args = false, progname = nil, &block) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/ree_lib/packages/ree_logger/package/ree_logger/multi_logger.rb', line 81

def warn(message = nil, parameters = {}, exception = nil, log_args = false, progname = nil, &block)
  if block_given?
    log_block(:warn, parameters, log_args, yield)
  else
    msg = get_message(message)
    log(:warn, msg, parameters, nil)
  end
end