Module: Bixby::Log
- Included in:
- APIChannel, APIChannel, WebSocket::Client
- Defined in:
- lib/bixby-common/util/log.rb,
lib/bixby-common/util/log/filtering_layout.rb
Overview
A simple logging mixin
Defined Under Namespace
Classes: FilteringLayout
Class Method Summary collapse
-
.setup_logger(opts = {}) ⇒ Object
Setup logging.
Instance Method Summary collapse
-
#log ⇒ Logger
(also: #logger)
Get a log instance for this class.
Class Method Details
.setup_logger(opts = {}) ⇒ Object
Setup logging
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bixby-common/util/log.rb', line 38 def self.setup_logger(opts={}) # set level: ENV flag overrides; default to warn opts[:level] = :debug if ENV["BIXBY_DEBUG"] opts[:level] ||= :warn pattern = opts.delete(:pattern) || '%.1l, [%d] %5l -- %c:%L: %m\n' layout = Logging.layouts.pattern(:pattern => pattern) opts[:filename] ||= Bixby.path("var", "bixby-agent.log") FileUtils.mkdir_p(File.dirname(opts[:filename])) # configure stdout appender (used in debug modes, etc) Logging.color_scheme( 'bright', :levels => { :info => :green, :warn => :yellow, :error => :red, :fatal => [:white, :on_red] }, :date => :blue, :logger => :cyan, :message => :magenta ) Logging.appenders.stdout( 'stdout', :auto_flushing => true, :layout => Logging.layouts.pattern( :pattern => pattern, :color_scheme => 'bright' ) ) # configure rolling file appender = { :keep => 7, :roll_by => 'date', :age => 'daily', :truncate => false, :auto_flushing => true, :layout => layout }.merge(opts) Logging.appenders.rolling_file("file", ) Logging::Logger.root.add_appenders("file") Logging::Logger.root.level = opts[:level] Logging::Logger.root.trace = true end |
Instance Method Details
#log ⇒ Logger Also known as: logger
Get a log instance for this class
15 16 17 |
# File 'lib/bixby-common/util/log.rb', line 15 def log @log ||= Logging.logger[self] end |