Class: Kuby::BasicLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/kuby/basic_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG, progname: nil, formatter: nil, datetime_format: nil, shift_period_suffix: '%Y%m%d') ⇒ BasicLogger

T::Sig::WithoutRuntime.sig

override.params(
  logdev: T.any(String, IO, StringIO, NilClass),
  shift_age: Integer,
  shift_size: Integer,
  level: Integer,
  progname: T.nilable(String),
  formatter: T.nilable(FormatterProcType),
  datetime_format: T.nilable(String),
  shift_period_suffix: T.nilable(String)
).void



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kuby/basic_logger.rb', line 22

def initialize(
    logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
    progname: nil, formatter: nil, datetime_format: nil,
    shift_period_suffix: '%Y%m%d')
  # @logdev = T.let(@logdev, T.nilable(Logger::LogDevice))

  super

  self.formatter = proc do |_severity, _datetime, _progname, msg|
    "#{msg}\n"
  end
end

Instance Method Details

#fatal(progname_or_msg = nil, &block) ⇒ Object

T::Sig::WithoutRuntime.sig

override.params(
  progname_or_msg: T.untyped,
  block: T.nilable(T.proc.returns(T.untyped))
).void



55
56
57
58
59
60
61
# File 'lib/kuby/basic_logger.rb', line 55

def fatal(progname_or_msg = nil, &block)
  if block
    super(progname_or_msg) { ColorizedString[block.call].red }
  else
    super(ColorizedString[progname_or_msg].red)
  end
end

#info(progname_or_msg = nil, &block) ⇒ Object

T::Sig::WithoutRuntime.sig

override.params(
  progname_or_msg: T.untyped,
  block: T.nilable(T.proc.returns(T.untyped))
).void



41
42
43
44
45
46
47
# File 'lib/kuby/basic_logger.rb', line 41

def info(progname_or_msg = nil, &block)
  if block
    super(progname_or_msg) { ColorizedString[block.call].yellow }
  else
    super(ColorizedString[progname_or_msg].yellow)
  end
end

#last_statusObject

T::Sig::WithoutRuntime.sig { returns(T.nilable(Process::Status)) }



80
81
82
# File 'lib/kuby/basic_logger.rb', line 80

def last_status
  nil
end

#with_pipes(out = STDOUT, err = STDERR, &block) ⇒ Object

adhere to the “CLI” interface T::Sig::WithoutRuntime.sig

params(
  out: T.any(IO, StringIO),
  err: T.any(IO, StringIO),
  block: T.proc.void
).void



71
72
73
74
75
76
77
# File 'lib/kuby/basic_logger.rb', line 71

def with_pipes(out = STDOUT, err = STDERR, &block)
  previous_logdev = @logdev&.dev || STDERR
  reopen(err)
  yield
ensure
  reopen(previous_logdev)
end