Module: ImportTools::ImportLogging::Include

Included in:
HammerCLIImport::BaseCommand, HammerCLIImport::ImportCommand::AllCommand
Defined in:
lib/hammer_cli_import/importtools.rb

Instance Method Summary collapse

Instance Method Details

#debug(s) ⇒ Object



281
282
283
# File 'lib/hammer_cli_import/importtools.rb', line 281

def debug(s)
  log(Logger::DEBUG, s)
end

#error(s) ⇒ Object



297
298
299
# File 'lib/hammer_cli_import/importtools.rb', line 297

def error(s)
  log(Logger::ERROR, s)
end

#fatal(s) ⇒ Object



301
302
303
# File 'lib/hammer_cli_import/importtools.rb', line 301

def fatal(s)
  log(Logger::FATAL, s)
end

#info(s) ⇒ Object



285
286
287
# File 'lib/hammer_cli_import/importtools.rb', line 285

def info(s)
  log(Logger::INFO, s)
end

#log(lvl, s, always = false) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/hammer_cli_import/importtools.rb', line 309

def log(lvl, s, always = false)
  @logger.log(lvl, s)
  return if option_quiet?

  if always
    puts s
  elsif option_verbose?
    puts s if lvl >= @curr_lvl
  else
    puts s if lvl > @curr_lvl
  end
end

#logtrace(e) ⇒ Object



305
306
307
# File 'lib/hammer_cli_import/importtools.rb', line 305

def logtrace(e)
  @logger.log(Logger::ERROR, (e.backtrace.join "\n"))
end

#progress(s) ⇒ Object



289
290
291
# File 'lib/hammer_cli_import/importtools.rb', line 289

def progress(s)
  log(Logger::INFO, s, true)
end

#setup_loggingObject



273
274
275
276
277
278
279
# File 'lib/hammer_cli_import/importtools.rb', line 273

def setup_logging
  @curr_lvl = Logger::INFO
  @curr_lvl = Logger::DEBUG if option_debug?

  @logger = Logger.new(File.new(option_logfile, 'a'))
  @logger.level = @curr_lvl
end

#warn(s) ⇒ Object



293
294
295
# File 'lib/hammer_cli_import/importtools.rb', line 293

def warn(s)
  log(Logger::WARN, s)
end