Class: CemAcpt::Logging::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/cem_acpt/logging.rb

Overview

Delagator class for the standard Ruby Logger class. This class is used to ensure the Github Actions formatter correctly formats the log output when using the standard Ruby Logger class methods such as #info, #debug, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logdev, shift_age = 0, shift_size = 1_048_576, **kwargs) ⇒ Logger

Returns a new instance of Logger.



74
75
76
77
78
79
80
81
82
# File 'lib/cem_acpt/logging.rb', line 74

def initialize(logdev, shift_age = 0, shift_size = 1_048_576, **kwargs)
  @config_hash = { logdev: logdev, shift_age: shift_age, shift_size: shift_size, **kwargs }
  @ci_mode = (kwargs[:formatter].downcase.to_sym == :github_action || !ENV['GITHUB_ACTIONS'].nil? || !ENV['CI'].nil?)
  kwargs[:formatter] = CemAcpt::Logging::Formatter.for(kwargs[:formatter]) if kwargs[:formatter]
  super(logdev, shift_age, shift_size, **kwargs)
  @raw_logdev = logdev # Used for logging from trap context
  @trap_context = false # If true, will not use the standard Logger methods and will write directly to the logdev
  @verbose = false
end

Instance Attribute Details

#config_hashObject (readonly)

Returns the value of attribute config_hash.



71
72
73
# File 'lib/cem_acpt/logging.rb', line 71

def config_hash
  @config_hash
end

#trap_contextObject

Returns the value of attribute trap_context.



72
73
74
# File 'lib/cem_acpt/logging.rb', line 72

def trap_context
  @trap_context
end

Instance Method Details

#debug(progname = nil, &block) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/cem_acpt/logging.rb', line 96

def debug(progname = nil, &block)
  severity = 'debug'
  return log_trap_context(severity, progname, &block) if log_trap_context?(severity)
  return log_ci_mode(severity, progname, &block) if log_ci_mode?(severity)

  super
end

#end_ci_groupObject



144
145
146
# File 'lib/cem_acpt/logging.rb', line 144

def end_ci_group
  self.<< "::endgroup::\n" if @ci_mode
end

#error(progname = nil, &block) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/cem_acpt/logging.rb', line 120

def error(progname = nil, &block)
  severity = 'error'
  return log_trap_context(severity, progname, &block) if log_trap_context?(severity)
  return log_ci_mode(severity, progname, &block) if log_ci_mode?(severity)

  super
end

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



128
129
130
131
132
133
134
# File 'lib/cem_acpt/logging.rb', line 128

def fatal(progname = nil, &block)
  severity = 'fatal'
  return log_trap_context(severity, progname, &block) if log_trap_context?(severity)
  return log_ci_mode(severity, progname, &block) if log_ci_mode?(severity)

  super
end

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



104
105
106
107
108
109
110
# File 'lib/cem_acpt/logging.rb', line 104

def info(progname = nil, &block)
  severity = 'info'
  return log_trap_context(severity, progname, &block) if log_trap_context?(severity)
  return log_ci_mode(severity, progname, &block) if log_ci_mode?(severity)

  super
end

#set_verbose(value) ⇒ Object

Raises:

  • (ArgumentError)


84
85
86
87
88
# File 'lib/cem_acpt/logging.rb', line 84

def set_verbose(value)
  raise ArgumentError, 'value must be a boolean' unless [true, false].include?(value)

  @verbose = value
end

#start_ci_group(name) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/cem_acpt/logging.rb', line 136

def start_ci_group(name)
  if @ci_mode
    self.<< "::group::#{name}\n"
  else
    info(name)
  end
end

#verbose(progname = nil, &block) ⇒ Object



90
91
92
93
94
# File 'lib/cem_acpt/logging.rb', line 90

def verbose(progname = nil, &block)
  return unless @verbose

  debug(progname, &block)
end

#warn(progname = nil, &block) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/cem_acpt/logging.rb', line 112

def warn(progname = nil, &block)
  severity = 'warn'
  return log_trap_context(severity, progname, &block) if log_trap_context?(severity)
  return log_ci_mode(severity, progname, &block) if log_ci_mode?(severity)

  super
end