Module: Chemlab::Runtime::Logger
- Included in:
- Configuration
- Defined in:
- lib/chemlab/runtime/logger.rb
Overview
Logger module
Instance Method Summary collapse
-
#log(obj, type = :info, **args) ⇒ Object
Log something to a stream.
Instance Method Details
#log(obj, type = :info, **args) ⇒ Object
Log something to a stream
16 17 18 19 20 21 22 23 24 |
# File 'lib/chemlab/runtime/logger.rb', line 16 def log(obj, type = :info, **args) raise ArgumentError, "Cannot log #{obj} as it does not respond to to_s!" unless obj.respond_to?(:to_s) args[:stream] = type.match?(/(err(or)?|warn(ing)?)/) ? $stderr : $stdout prefix = Time.now.strftime('%Y-%m-%d %H:%M:%S / ') prefix << type[0..3].upcase << "\t:: " # we only want the prefix to be four chars long args[:stream].puts(prefix << obj.to_s) end |