Class: Contrast::Logger::Log

Inherits:
Object
  • Object
show all
Includes:
Utils::LogUtils, Singleton
Defined in:
lib/contrast/logger/log.rb

Overview

This class functions to serve as a wrapper around our logging, as we need to be able to dynamically update level based on updates to TeamServer.

Constant Summary

Constants included from Utils::LogUtils

Utils::LogUtils::DATE_TIME_FORMAT, Utils::LogUtils::DEFAULT_LEVEL, Utils::LogUtils::DEFAULT_NAME, Utils::LogUtils::PROGNAME, Utils::LogUtils::STDERR_STR, Utils::LogUtils::STDOUT_STR, Utils::LogUtils::VALID_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::LogUtils

#write_permission?

Constructor Details

#initializeLog

Returns a new instance of Log.



46
47
48
# File 'lib/contrast/logger/log.rb', line 46

def initialize
  update
end

Instance Attribute Details

#previous_levelObject (readonly)

Returns the value of attribute previous_level.



44
45
46
# File 'lib/contrast/logger/log.rb', line 44

def previous_level
  @previous_level
end

#previous_pathObject (readonly)

Returns the value of attribute previous_path.



44
45
46
# File 'lib/contrast/logger/log.rb', line 44

def previous_path
  @previous_path
end

Instance Method Details

#loggerObject



85
86
87
# File 'lib/contrast/logger/log.rb', line 85

def logger
  @_logger
end

#update(log_file = nil, log_level = nil) ⇒ Object

Given new settings from TeamServer, update our logging to use the new file and level, assuming they weren’t set by local configuration.

Parameters:

  • log_file (String) (defaults to: nil)

    the file to which to log, as provided by TeamServer settings

  • log_level (String) (defaults to: nil)

    the level at which to log, as provided by TeamServer settings



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/contrast/logger/log.rb', line 55

def update log_file = nil, log_level = nil
  current_path        = find_valid_path(log_file)
  current_level_const = find_valid_level(log_level)

  path_change = current_path != previous_path
  level_change = current_level_const != previous_level

  # don't needlessly recreate logger
  return if @_logger && !(path_change || level_change)

  @previous_path  = current_path
  @previous_level = current_level_const

  progname = Contrast::CONFIG.agent.logger.progname
  @_logger = build(path: current_path, level_const: current_level_const, progname: progname)
  # If we're logging to a new path, then let's start it w/ our helpful
  # data gathering messages
  log_update if path_change
rescue StandardError => e
  if logger
    logger.error('Unable to process update to LoggerManager.', e)
  else
    puts('Unable to process update to LoggerManager.')
    raise(e) if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']

    puts(e.message)
    puts(e.backtrace.join("\n"))
  end
end