Class: Candle::LoggerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/candle/logger.rb

Overview

Configuration helper for logger setup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoggerConfig

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

#formatterObject

Returns the value of attribute formatter.



54
55
56
# File 'lib/candle/logger.rb', line 54

def formatter
  @formatter
end

#levelObject

Returns the value of attribute level.



54
55
56
# File 'lib/candle/logger.rb', line 54

def level
  @level
end

#outputObject

Returns the value of attribute output.



54
55
56
# File 'lib/candle/logger.rb', line 54

def output
  @output
end

Instance Method Details

#build_loggerLogger

Build a logger from the configuration

Returns:

  • (Logger)

    Configured logger



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

Parameters:

  • file_path (String)

    Path to log 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