Module: Logging
- Included in:
- Grafana::Client
- Defined in:
- lib/grafana/logging.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.configure_logger_for(classname) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/grafana/logging.rb', line 21 def configure_logger_for( classname ) log_level = ENV.fetch('LOG_LEVEL', 'INFO' ) level = log_level.dup # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN log_level = case level.upcase when 'DEBUG' Logger::DEBUG # Low-level information for developers. when 'INFO' Logger::INFO # Generic (useful) information about system operation. when 'WARN' Logger::WARN # A warning. when 'ERROR' Logger::ERROR # A handleable error condition. when 'FATAL' Logger::FATAL # An unhandleable error that results in a program crash. else Logger::UNKNOWN # An unknown message that should always be logged. end $stdout.sync = true logger = Logger.new($stdout) logger.level = log_level logger.datetime_format = "%Y-%m-%d %H:%M:%S %z" logger.formatter = proc do |severity, datetime, progname, msg| "[#{datetime.strftime( logger.datetime_format )}] #{severity.ljust(5)} #{msg}\n" end logger end |
.logger_for(classname) ⇒ Object
17 18 19 |
# File 'lib/grafana/logging.rb', line 17 def logger_for( classname ) @loggers[classname] ||= configure_logger_for( classname ) end |
Instance Method Details
#logger ⇒ Object
8 9 10 |
# File 'lib/grafana/logging.rb', line 8 def logger @logger ||= Logging.logger_for( self.class.name ) end |