class Config
Represents a configuration for the traces library.
Definitions
def self.load(path)
Load the configuration from the given path.
Signature
-
parameter
path
String
The path to the configuration file.
-
returns
Config
The loaded configuration.
Implementation
def self.load(path)
config = self.new
if File.exist?(path)
config.instance_eval(File.read(path), path)
end
return config
end
def self.default
Load the default configuration.
Signature
-
returns
Config
The default configuration.
Implementation
def self.default
@default ||= self.load(PATH)
end
def log_level(env = ENV)
Set the default log level based on $DEBUG
and $VERBOSE
.
You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
Implementation
def log_level(env = ENV)
Logger.default_log_level(env)
end
def verbose?(env = ENV)
Controls verbose output using $VERBOSE
.
Implementation
def verbose?(env = ENV)
!$VERBOSE.nil? || env["CONSOLE_VERBOSE"]
end
def make_output(io = nil, env = ENV, **options)
Create an output with the given output and options.
Signature
-
parameter
output
IO
The output to write log messages to.
-
parameter
env
Hash
The environment to read configuration from.
-
parameter
options
Hash
Additional options to pass to the output.
-
returns
Output
The created output.
Implementation
def make_output(io = nil, env = ENV, **options)
Output.new(io, env, **options)
end
def make_resolver(logger)
Create a resolver with the given logger.
Signature
-
parameter
logger
Logger
The logger to set the log levels on.
-
returns
Resolver | Nil
The created resolver.
Implementation
def make_resolver(logger)
Resolver.default_resolver(logger)
end
def make_logger(io = $stderr, env = ENV, **options)
Create a logger with the given output and options.
Signature
-
parameter
output
IO
The output to write log messages to.
-
parameter
env
Hash
The environment to read configuration from.
-
parameter
options
Hash
Additional options to pass to the logger.
-
returns
Logger
The created logger.
Implementation
def make_logger(io = $stderr, env = ENV, **options)
if options[:verbose].nil?
options[:verbose] = self.verbose?(env)
end
if options[:level].nil?
options[:level] = self.log_level(env)
end
output = self.make_output(io, env, **options)
logger = Logger.new(output, **options)
make_resolver(logger)
return logger
end
DEFAULT = self.default
Load the default configuration.