Class: Candle::LoggerConfig
- Inherits:
-
Object
- Object
- Candle::LoggerConfig
- Defined in:
- lib/candle/logger.rb
Overview
Configuration helper for logger setup
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#level ⇒ Object
Returns the value of attribute level.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
-
#build_logger ⇒ Logger
Build a logger from the configuration.
-
#disable! ⇒ Object
Disable logging completely.
-
#info! ⇒ Object
Set log level to info.
-
#initialize ⇒ LoggerConfig
constructor
A new instance of LoggerConfig.
-
#log_to_file!(file_path) ⇒ Object
Log to a file.
-
#log_to_stdout! ⇒ Object
Log to stdout instead of stderr.
-
#quiet! ⇒ Object
Set log level to warn (default).
-
#silent! ⇒ Object
Set log level to error (minimal output).
-
#verbose! ⇒ Object
Set log level to debug (verbose output).
Constructor Details
#initialize ⇒ LoggerConfig
Returns a new instance of LoggerConfig.
56 57 58 59 60 |
# File 'lib/candle/logger.rb', line 56 def initialize @level = :warn @output = $stderr @formatter = :simple end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
54 55 56 |
# File 'lib/candle/logger.rb', line 54 def formatter @formatter end |
#level ⇒ Object
Returns the value of attribute level.
54 55 56 |
# File 'lib/candle/logger.rb', line 54 def level @level end |
#output ⇒ Object
Returns the value of attribute output.
54 55 56 |
# File 'lib/candle/logger.rb', line 54 def output @output end |
Instance Method Details
#build_logger ⇒ Logger
Build a logger from the configuration
64 65 66 67 68 69 |
# File 'lib/candle/logger.rb', line 64 def build_logger logger = Logger.new(@output) logger.level = normalize_level(@level) logger.formatter = build_formatter(@formatter) logger end |
#disable! ⇒ Object
Disable logging completely
103 104 105 |
# File 'lib/candle/logger.rb', line 103 def disable! @output = File::NULL end |
#info! ⇒ Object
Set log level to info
77 78 79 |
# File 'lib/candle/logger.rb', line 77 def info! @level = :info end |
#log_to_file!(file_path) ⇒ Object
Log to a file
98 99 100 |
# File 'lib/candle/logger.rb', line 98 def log_to_file!(file_path) @output = file_path end |
#log_to_stdout! ⇒ Object
Log to stdout instead of stderr
92 93 94 |
# File 'lib/candle/logger.rb', line 92 def log_to_stdout! @output = $stdout end |
#quiet! ⇒ Object
Set log level to warn (default)
82 83 84 |
# File 'lib/candle/logger.rb', line 82 def quiet! @level = :warn end |
#silent! ⇒ Object
Set log level to error (minimal output)
87 88 89 |
# File 'lib/candle/logger.rb', line 87 def silent! @level = :error end |
#verbose! ⇒ Object
Set log level to debug (verbose output)
72 73 74 |
# File 'lib/candle/logger.rb', line 72 def verbose! @level = :debug end |