Class: Spectre::Logger
Overview
An extended Logger class providing additional Spectre run information
Instance Method Summary collapse
- #correlate ⇒ Object
-
#initialize(config) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(config) ⇒ Logger
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/spectre.rb', line 194 def initialize(config, **) log_file = config['log_file'] FileUtils.mkdir_p(File.dirname(log_file)) if log_file.is_a? String super(log_file, **) if config['debug'] debug! else info! end @corr_ids = [] @formatter = proc do |severity, datetime, progname, | date_formatted = datetime.strftime(config['log_date_format']) progname ||= 'spectre' corr_id = @corr_ids.join # Add log message also to the current executing run context if RunContext.current.nil? context_name = 'spectre' else RunContext.current.logs << [date_formatted, severity, progname, corr_id, ] context_name = RunContext.current.name end format(config['log_message_format'], date_formatted, severity, progname, context_name, corr_id, ) end end |
Instance Method Details
#correlate ⇒ Object
233 234 235 236 237 238 239 240 241 |
# File 'lib/spectre.rb', line 233 def correlate @corr_ids.append(rand(36**4).to_s(36)) begin yield ensure @corr_ids.pop end end |