Class: Mixlib::Log::Logger

Inherits:
Logger
  • Object
show all
Includes:
Logging
Defined in:
lib/mixlib/log/logger.rb

Defined Under Namespace

Classes: LocklessLogDevice

Constant Summary

Constants included from Logging

Mixlib::Log::Logging::LEVELS, Mixlib::Log::Logging::LEVEL_NAMES, Mixlib::Log::Logging::SEV_LABEL, Mixlib::Log::Logging::TRACE

Instance Attribute Summary

Attributes included from Logging

#metadata

Instance Method Summary collapse

Methods included from Logging

#pass, #to_label

Constructor Details

#initialize(logdev) ⇒ Logger

Synopsis

Logger.new(name, shift_age = 7, shift_size = 1048576)
Logger.new(name, shift_age = 'weekly')

Args

logdev

The log device. This is a filename (String) or IO object (typically $stdout, $stderr, or an open file).

shift_age

Number of old log files to keep, or frequency of rotation (daily, weekly or monthly).

shift_size

Maximum logfile size (only applies when shift_age is a number).

Description

Create an instance.



35
36
37
38
39
40
# File 'lib/mixlib/log/logger.rb', line 35

def initialize(logdev)
  super(nil)
  if logdev
    @logdev = LocklessLogDevice.new(logdev)
  end
end

Instance Method Details

#add_data(severity, message, progname, data: {}) ⇒ Object Also known as: add



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mixlib/log/logger.rb', line 42

def add_data(severity, message, progname, data: {})
  return true if @logdev.nil? || severity < @level

  data ||= {}
  if message.is_a?(::Exception)
    data[:err] = message
  else
    data[:msg] = message
  end
  @logdev.write(
    format_message(to_label(severity), Time.now, progname, data)
  )
  true
end

#trace?Boolean

Returns:

  • (Boolean)


12
# File 'lib/mixlib/log/logger.rb', line 12

def trace?; @level <= TRACE; end