module SignalFx::Tracing::Logging
Constants
- DEFAULT_LOG_PATH
- DEFAULT_SHIFT_AGE
- DEFAULT_SHIFT_SIZE
- LOG_LEVELS
Public Class Methods
create(log_path = ENV['SIGNALFX_LOG_PATH'] || DEFAULT_LOG_PATH, sfx_shift_age = ENV['SIGNALFX_LOG_SHIFT_AGE'] || DEFAULT_SHIFT_AGE, sfx_shift_size = ENV['SIGNALFX_LOG_SHIFT_SIZE'] || DEFAULT_SHIFT_SIZE)
click to toggle source
# File lib/signalfx/tracing/sfx_logger.rb, line 20 def self.create (log_path = ENV['SIGNALFX_LOG_PATH'] || DEFAULT_LOG_PATH, sfx_shift_age = ENV['SIGNALFX_LOG_SHIFT_AGE'] || DEFAULT_SHIFT_AGE, sfx_shift_size = ENV['SIGNALFX_LOG_SHIFT_SIZE'] || DEFAULT_SHIFT_SIZE) if log_path.upcase == 'STDOUT' @logger = Logger.new(STDOUT) elsif log_path.upcase == 'STDERR' self.create_stderr_logger() else begin @logger = Logger.new("#{log_path}", shift_age = sfx_shift_age, shift_size = sfx_shift_size) rescue Errno::EACCES, Errno::ENOENT => e self.create_stderr_logger(log_path, e) end end log_level = ENV['SIGNALFX_LOG_LEVEL'].downcase if ENV['SIGNALFX_LOG_LEVEL'] @logger.level = LOG_LEVELS.fetch(log_level, Logger::WARN) @logger.datetime_format = '%Y-%m-%d %H:%M:%S' @logger.formatter = proc do | severity, datetime, progname, msg | "#{datetime}, #{severity}: #{msg} --- #{progname} \n" end @logger end
create_stderr_logger(logpath=nil, error=nil)
click to toggle source
# File lib/signalfx/tracing/sfx_logger.rb, line 49 def self.create_stderr_logger(logpath=nil, error=nil) @logger = Logger.new(STDERR) if error @logger.error { "LOG FILE ACCESS ERROR:\n*** Failed to write to '#{logpath}': #{error.message}\n--> Please manually create the required resources and/or grant relevant access permissions to this user process.\n*** Defaulting to sending log statements to the standard error (STDERR) handle.\n"} end end
logger()
click to toggle source
# File lib/signalfx/tracing/sfx_logger.rb, line 45 def self.logger @logger ||= self.create end