class Lug::Device
Attributes
io[R]
Public Class Methods
new(io = STDERR)
click to toggle source
Create a Device
associated to an io
instance
@param io [IO] (default: STDERR)
# File lib/lug/logger.rb, line 116 def initialize(io = STDERR) @io = io @io.sync = true @enabled_namespaces = [] enable(ENV['DEBUG'.freeze].to_s) if ENV['DEBUG'] end
Public Instance Methods
enable(filter)
click to toggle source
Updates list of enabled namespaces for this device based on filter
@param filter [String] @return [Array<Regexp>] list of namespace filter regexps
# File lib/lug/logger.rb, line 167 def enable(filter) @enabled_namespaces = Helpers.parse_namespace_filter(filter) end
enabled_for?(namespace)
click to toggle source
Decides whether namespace
is enabled on this device
@param namespace [String, Symbol] @return [Boolean]
# File lib/lug/logger.rb, line 157 def enabled_for?(namespace) ns = namespace.to_s @enabled_namespaces.any? { |re| ns =~ re } end
log(message, namespace = nil)
click to toggle source
Log a message
to output device, within a namespace
@param message [String] @param namespace [String, Symbol] (default: nil) @return [NilClass]
# File lib/lug/logger.rb, line 130 def log(message, namespace = nil) line = [ Time.now, $$, namespace && "[#{namespace}]", message ].compact.join(' '.freeze) @io.write("#{line}\n") nil end
Also aliased as: <<
on(namespace)
click to toggle source
Clone logger with the same device and namespace
appended
@param namespace [String, Symbol] @return [Lug::Logger]
# File lib/lug/logger.rb, line 148 def on(namespace) Logger.new(self, namespace) end