Class: Ghaki::Logger::Base

Inherits:
Logger
  • Object
show all
Includes:
Liner
Defined in:
lib/ghaki/logger/base.rb

Direct Known Subclasses

Null

Instance Attribute Summary collapse

Attributes included from Liner

#box_char, #box_size

Attributes included from CoreExt::Logger

#logdev

Instance Method Summary collapse

Methods included from Liner

#box, #fatal_dump, #liner, #puts

Methods included from CoreExt::Logger

#bounce, #re_open, #re_stderr, #re_stdout, #re_stds, #rotate

Constructor Details

#initialize(opts = {}) ⇒ Base

Constructor options:

box_char

Character used to make line separators in the logs.

box_size

Line length used for separators in the logs.

datetime_format

Date/time format used for logging.

file_handle

Open file handle to log to.

file_name

Name of file to open for logging.

level

Verbosity of logging.

shift_age
Shift age for logs, see ::Logger

for details.

shift_size

Shift size for logs, see ::Logger for details.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ghaki/logger/base.rb', line 34

def initialize opts={}

  setup_liner opts

  @major = Ghaki::Logger::Wrapper::Major.new({
    :logger   => self,
    :box_char => opts[:box_char],
    :box_size => opts[:box_size],
  })

  @minor = Ghaki::Logger::Wrapper::Minor.new({
    :logger => self,
  })

  if opts[:log_device].nil?
    super( *([
      opts[:file_handle] || opts[:file_name] || $stderr,
      opts[:shift_age],
      opts[:shift_size]
    ].compact) )
  else
    super(nil)
    self.logdev = opts[:log_device]
  end

  self.level = opts[:level] || DEF_LEVEL
  self.datetime_format = opts[:datetime_format] || DEF_DATETIME_FORMAT
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



15
16
17
# File 'lib/ghaki/logger/base.rb', line 15

def major
  @major
end

#minorObject

Returns the value of attribute minor.



15
16
17
# File 'lib/ghaki/logger/base.rb', line 15

def minor
  @minor
end

Instance Method Details

#dupObject

Create similar logger that uses the same log device.



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ghaki/logger/base.rb', line 73

def dup
  Ghaki::Logger::Base.new({
    :log_device      => self.logdev,
    :level           => self.level,
    :datetime_format => self.datetime_format,
    :shift_age       => self.shift_age,
    :shift_size      => self.shift_size,
    :box_char        => self.box_char,
    :box_size        => self.box_size,
  })
end

#level=(val) ⇒ Object

Set logging level. Assert on invalid level.

Raises:

  • (ArgumentError)


65
66
67
68
69
# File 'lib/ghaki/logger/base.rb', line 65

def level= val
  val = SEVERITY_LOOKUP[val]
  raise ArgumentError, "Invalid log level: #{val}" if val.nil?
  super(val)
end