Class: Chemicalml::Logger
- Inherits:
-
Logger
- Object
- Logger
- Chemicalml::Logger
- Defined in:
- lib/chemicalml/logger.rb
Overview
Logger used across the CLI and API. Wraps Ruby's ::Logger and can
bridge to Thor's say / say_error when running under a Thor
dispatcher — that gives coloured output on the terminal while
plain Logger.new($stderr) works for library callers.
Severity routing under Thor:
debug → suppressed (set level manually if needed)
info → say (green-ish, $stdout)
warn → say_error with :yellow ($stderr)
error → say_error with :red ($stderr)
fatal → say_error with :red ($stderr)
Instance Attribute Summary collapse
-
#thor_shell ⇒ Object
Returns the value of attribute thor_shell.
Class Method Summary collapse
-
.default ⇒ Object
Convenience: create a default logger that writes to $stderr at INFO level.
Instance Method Summary collapse
Instance Attribute Details
#thor_shell ⇒ Object
Returns the value of attribute thor_shell.
18 19 20 |
# File 'lib/chemicalml/logger.rb', line 18 def thor_shell @thor_shell end |
Class Method Details
.default ⇒ Object
Convenience: create a default logger that writes to $stderr at INFO level. Used when no logger is explicitly provided.
43 44 45 |
# File 'lib/chemicalml/logger.rb', line 43 def self.default new($stderr).tap { |l| l.level = INFO } end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chemicalml/logger.rb', line 26 def add(severity, = nil, progname = nil) return super unless thor_shell return true if severity < level msg = || progname case severity when ERROR, FATAL thor_shell.say_error(msg.to_s, :red) when WARN thor_shell.say_error(msg.to_s, :yellow) else thor_shell.say(msg.to_s) end end |