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