Class: CemAcpt::Logging::Logger
- Inherits:
-
Logger
- Object
- Logger
- CemAcpt::Logging::Logger
- 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
-
#config_hash ⇒ Object
readonly
Returns the value of attribute config_hash.
-
#trap_context ⇒ Object
Returns the value of attribute trap_context.
Instance Method Summary collapse
- #debug(progname = nil, &block) ⇒ Object
- #error(progname = nil, &block) ⇒ Object
- #fatal(progname = nil, &block) ⇒ Object
- #info(progname = nil, &block) ⇒ Object
-
#initialize(logdev, shift_age = 0, shift_size = 1_048_576, **kwargs) ⇒ Logger
constructor
A new instance of Logger.
- #set_verbose(value) ⇒ Object
- #verbose(progname = nil, &block) ⇒ Object
- #warn(progname = nil, &block) ⇒ Object
-
#with_ci_group(name) ⇒ Object
Wraps the given block in a Github Actions group if in CI mode.
Constructor Details
#initialize(logdev, shift_age = 0, shift_size = 1_048_576, **kwargs) ⇒ Logger
Returns a new instance of Logger.
69 70 71 72 73 74 75 76 77 |
# File 'lib/cem_acpt/logging.rb', line 69 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_hash ⇒ Object (readonly)
Returns the value of attribute config_hash.
66 67 68 |
# File 'lib/cem_acpt/logging.rb', line 66 def config_hash @config_hash end |
#trap_context ⇒ Object
Returns the value of attribute trap_context.
67 68 69 |
# File 'lib/cem_acpt/logging.rb', line 67 def trap_context @trap_context end |
Instance Method Details
#debug(progname = nil, &block) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/cem_acpt/logging.rb', line 91 def debug(progname = nil, &block) return if log_trap_context('debug', progname, &block) return if log_ci_mode('debug', progname, &block) super end |
#error(progname = nil, &block) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/cem_acpt/logging.rb', line 112 def error(progname = nil, &block) return if log_trap_context('error', progname, &block) return if log_ci_mode('error', progname, &block) super end |
#fatal(progname = nil, &block) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/cem_acpt/logging.rb', line 119 def fatal(progname = nil, &block) return if log_trap_context('fatal', progname, &block) return if log_ci_mode('fatal', progname, &block) super end |
#info(progname = nil, &block) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/cem_acpt/logging.rb', line 98 def info(progname = nil, &block) return if log_trap_context('info', progname, &block) return if log_ci_mode('info', progname, &block) super end |
#set_verbose(value) ⇒ Object
79 80 81 82 83 |
# File 'lib/cem_acpt/logging.rb', line 79 def set_verbose(value) raise ArgumentError, 'value must be a boolean' unless [true, false].include?(value) @verbose = value end |
#verbose(progname = nil, &block) ⇒ Object
85 86 87 88 89 |
# File 'lib/cem_acpt/logging.rb', line 85 def verbose(progname = nil, &block) return unless @verbose debug(progname, &block) end |
#warn(progname = nil, &block) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/cem_acpt/logging.rb', line 105 def warn(progname = nil, &block) return if log_trap_context('warn', progname, &block) return if log_ci_mode('warn', progname, &block) super end |
#with_ci_group(name) ⇒ Object
Wraps the given block in a Github Actions group if in CI mode
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/cem_acpt/logging.rb', line 128 def with_ci_group(name) if @ci_mode self.<< "::group::#{name}\n" else info(name) end yield ensure self.<< "::endgroup::\n" if @ci_mode end |