Class: ScoutApm::Logging::Loggers::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/logging/loggers/logger.rb

Overview

The newly created logger which we can configure, and will log to a filepath.

Constant Summary collapse

LOG_AGE =

1 log file

1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, log_instance) ⇒ Logger

Returns a new instance of Logger.



33
34
35
36
# File 'lib/scout_apm/logging/loggers/logger.rb', line 33

def initialize(context, log_instance)
  @context = context
  @log_instance = log_instance
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



28
29
30
# File 'lib/scout_apm/logging/loggers/logger.rb', line 28

def context
  @context
end

#log_instanceObject (readonly)

Returns the value of attribute log_instance.



28
29
30
# File 'lib/scout_apm/logging/loggers/logger.rb', line 28

def log_instance
  @log_instance
end

Instance Method Details

#create_logger!Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/scout_apm/logging/loggers/logger.rb', line 38

def create_logger!
  # We create the file in order to prevent a creation header log.
  File.new(determine_file_path, 'w+') unless File.exist?(determine_file_path)
  log_size = context.config.value('logs_log_file_size')

  FileLogger.new(determine_file_path, LOG_AGE, log_size).tap do |logger|
    # Ruby's Logger handles a lot of the coercion itself.
    logger.level = determined_log_level
    # Add our custom formatter to the logger.
    logger.formatter = Formatter.new
  end
end

#determine_file_pathObject

rubocop:disable Metrics/AbcSize



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/scout_apm/logging/loggers/logger.rb', line 51

def determine_file_path # rubocop:disable Metrics/AbcSize
  log_directory = context.config.value('logs_proxy_log_dir')

  original_basename = File.basename(log_destination) if log_destination.is_a?(String)

  file_basename = if original_basename
                    original_basename
                  elsif defined?(::ActiveSupport::Logger) && log_instance.is_a?(::ActiveSupport::Logger)
                    'rails.log'
                  elsif defined?(::ActiveSupport::BroadcastLogger) && log_instance.is_a?(::ActiveSupport::BroadcastLogger)
                    'rails.log'
                  elsif defined?(::Sidekiq::Logger) && log_instance.is_a?(::Sidekiq::Logger)
                    'sidekiq.log'
                  elsif defined?(::ScoutTestLogger) && log_instance.is_a?(::ScoutTestLogger)
                    'test.log'
                  else
                    'mix.log'
                  end

  File.join(log_directory, file_basename)
end