Class: Log15::Logger

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger = Rails.logger) ⇒ Logger

Returns a new instance of Logger.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/log15/logger.rb', line 7

def initialize(logger=Rails.logger)
  @logger = logger.dup
  @logger.formatter = proc do |severity, datetime, progname, msg|
    date = "#{datetime.month}-#{datetime.day}"
    time = "#{pad(datetime.hour)}:#{pad(datetime.min)}:#{pad(datetime.sec)}"
    severities = { "ERROR" => "EROR", "DEBUG" => "DBUG" }
    original_severity = severity
    severity = severities.fetch(severity, severity)
    "#{severity}[#{date}|#{time}] #{msg} lvl=#{original_severity.downcase}\n"
  end
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/log15/logger.rb', line 6

def logger
  @logger
end

Class Method Details

.defaultObject



19
20
21
# File 'lib/log15/logger.rb', line 19

def self.default
  @logger ||= Log15::Logger.new
end

.sanitize(params, key, opts = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/log15/logger.rb', line 23

def self.sanitize(params, key, opts={})
  if params[key]
    raise SanitizationError, "expected #{key} to not be blank" if params[key] == ""
    if opts[:expected_length]
      minimum_size = opts[:expected_length].first
      maximum_size = opts[:expected_length].last
      length = params[key].length
      if length < minimum_size || length > maximum_size
        raise SanitizationError, "expected access_token to be between #{minimum_size} and #{maximum_size} characters long (is #{length})"
      end
    end
    params[key] = params[key][0..5] + "****" + params[key][-6..-1]
  else
    raise SanitizationError, "expected #{key} to be present"
  end
  params
end

Instance Method Details

#debug(msg, data = {}) ⇒ Object



41
42
43
# File 'lib/log15/logger.rb', line 41

def debug(msg, data={})
  logger.debug(process(msg, data))
end

#error(msg, data = {}) ⇒ Object



53
54
55
# File 'lib/log15/logger.rb', line 53

def error(msg, data={})
  logger.error(process(msg, data))
end

#info(msg, data = {}) ⇒ Object



45
46
47
# File 'lib/log15/logger.rb', line 45

def info(msg, data={})
  logger.info(process(msg, data))
end

#warn(msg, data = {}) ⇒ Object



49
50
51
# File 'lib/log15/logger.rb', line 49

def warn(msg, data={})
  logger.warn(process(msg, data))
end