Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jrothrock committed May 7, 2024
1 parent 7ed2492 commit d804561
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 43 deletions.
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ Naming/FileName:
Style/Documentation:
Enabled: true

Naming/PredicateName:
Enabled: false

Style/ClassVars:
Enabled: false

Metrics/MethodLength:
Max: 20

Lint/LiteralAsCondition:
Enabled: false

Layout/LineLength:
Max: 130

Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%w': "[]"
Expand Down
44 changes: 23 additions & 21 deletions lib/scout_apm/logging/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,56 @@

module ScoutApm
module Logging
# Holds the configuration values for Scout APM Logging.
class Config < ScoutApm::Config
KNOWN_CONFIG_OPTIONS = [
'config_file',
'log_level',
'log_stderr',
'log_stdout',
'log_file_path',
'log_class',
'logging_ingest_key',
'logging_monitor',
'monitor_pid_file'
]
KNOWN_CONFIG_OPTIONS = %w[
config_file
log_level
log_stderr
log_stdout
log_file_path
log_class
logging_ingest_key
logging_monitor
monitor_pid_file
].freeze

SETTING_COERCIONS = {
'monitor_logs' => BooleanCoercion.new,
}
'monitor_logs' => BooleanCoercion.new
}.freeze

def self.with_file(context, file_path=nil, config={})
def self.with_file(context, file_path = nil, config = {})
overlays = [
ConfigEnvironment.new,
ConfigFile.new(context, file_path, config),
ConfigDefaults.new,
ConfigNull.new,
ConfigNull.new
]
new(context, overlays)
end

# Defaults in case no config file has been found.
class ConfigDefaults
DEFAULTS = {
'log_level' => 'info',
'monitor_pid_file' => '/tmp/scout_apm_log_monitor.pid',
'monitor_pid_file' => '/tmp/scout_apm_log_monitor.pid'
}.freeze

def value(key)
DEFAULTS[key]
end

def has_key?(key)
DEFAULTS.has_key?(key)
DEFAULTS.key?(key)
end

# Defaults are here, but not counted as user specified.
# Defaults are here, but not counted as user specified.
def any_keys_found?
false
end

def name
"defaults"
'defaults'
end
end
end
Expand Down
25 changes: 13 additions & 12 deletions lib/scout_apm/logging/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

module ScoutApm
module Logging
# Contains context around Scout APM logging, such as environment, configuration, and the logger.
class Context
# Initially start up without attempting to load a configuration file. We
# need to be able to lookup configuration options like "application_root"
# which would then in turn influence where the yaml configuration file is
# located
#
# Later in initialization, we set config= to include the file.
def initialize()
def initialize
@logger = LoggerFactory.build_minimal_logger
end

Expand All @@ -27,29 +28,29 @@ def logger

def config=(config)
@config = config

@logger = nil

# TODO
# log_configuration_settings
end
end

# Create a logger based on the configuration settings.
class LoggerFactory
def self.build(config, environment)
ScoutApm::Logging::Logger.new(environment.root,
{
:log_level => config.value('log_level'),
:log_file_path => config.value('log_file_path'),
:stdout => config.value('log_stdout') || environment.platform_integration.log_to_stdout?,
:stderr => config.value('log_stderr'),
:logger_class => config.value('log_class'),
}
)
{
log_level: config.value('log_level'),
log_file_path: config.value('log_file_path'),
stdout: config.value('log_stdout') || environment.platform_integration.log_to_stdout?,
stderr: config.value('log_stderr'),
logger_class: config.value('log_class')
})
end

def self.build_minimal_logger
ScoutApm::Logging::Logger.new(nil, :stdout => true)
ScoutApm::Logging::Logger.new(nil, stdout: true)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/scout_apm/logging/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

module ScoutApm
module Logging
# Custom logger for ScoutApm Logging.
class Logger < ScoutApm::Logger

private

def determine_log_destination
case true
when stdout?
STDOUT
$stdout
when stderr?
STDERR
$stderr
when validate_path(@opts[:log_file])
@opts[:log_file]
when validate_path("#{log_file_path}/scout_apm_logging.log")
"#{log_file_path}/scout_apm_logging.log"
else
# Safe fallback
STDOUT
$stdout
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/scout_apm/logging/monitor/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.instance

def initialize
@context = ScoutApm::Logging::Context.new
context.config = ScoutApm::Logging::Config.with_file(context, context.config.value("config_file"))
context.config = ScoutApm::Logging::Config.with_file(context, context.config.value('config_file'))
end

def setup!
Expand All @@ -44,7 +44,7 @@ def run!

def add_exit_handler
at_exit do
File.delete(context.config.value("monitor_pid_file"))
File.delete(context.config.value('monitor_pid_file'))
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/scout_apm/logging/monitor_manager/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ def self.instance

def initialize
@context = ScoutApm::Logging::Context.new
context.config = ScoutApm::Logging::Config.with_file(context, context.config.value("config_file"))
context.config = ScoutApm::Logging::Config.with_file(context, context.config.value('config_file'))
end

def setup!
create_process
end

def create_process
return if File.exist? context.config.value("monitor_pid_file")
return if File.exist? context.config.value('monitor_pid_file')

gem_directory = File.expand_path('../../../..', __dir__)
daemon_process = Process.spawn("ruby #{gem_directory}/bin/scout_apm_logging_monitor", pgroup: true)

File.write(context.config.value("monitor_pid_file"), daemon_process)
File.write(context.config.value('monitor_pid_file'), daemon_process)

# TODO: Add exit handlers?
end
Expand Down
2 changes: 1 addition & 1 deletion spec/scout_apm_logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

it 'checks lifecycle of the daemon process' do
pid_file = ScoutApm::Logging::MonitorManager.instance.context.config.value("monitor_pid_file")
pid_file = ScoutApm::Logging::MonitorManager.instance.context.config.value('monitor_pid_file')

# Check if the PID file exists
expect(File.exist?(pid_file)).to be_truthy
Expand Down

0 comments on commit d804561

Please sign in to comment.