Class: Lug::Device
- Inherits:
-
Object
- Object
- Lug::Device
- Defined in:
- lib/lug/logger.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Attributes included from Standard::DeviceMethods
Instance Method Summary collapse
-
#enable(filter) ⇒ Array<Regexp>
Updates list of enabled namespaces for this device based on
filter
. -
#enabled_for?(namespace) ⇒ Boolean
Decides whether
namespace
is enabled on this device. -
#initialize(io = STDERR) ⇒ Device
constructor
Create a Device associated to an
io
instance. -
#log(message, namespace = nil) ⇒ NilClass
(also: #<<)
Log a
message
to output device, within anamespace
. -
#on(namespace) ⇒ Lug::Logger
Clone logger with the same device and
namespace
appended.
Methods included from Standard::LoggerDeviceMethods
#debug, #error, #fatal, #info, #unknown, #warn
Constructor Details
#initialize(io = STDERR) ⇒ Device
Create a Device associated to an io
instance
116 117 118 119 120 121 122 |
# 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 |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
110 111 112 |
# File 'lib/lug/logger.rb', line 110 def io @io end |
Instance Method Details
#enable(filter) ⇒ Array<Regexp>
Updates list of enabled namespaces for this device based on filter
167 168 169 |
# File 'lib/lug/logger.rb', line 167 def enable(filter) @enabled_namespaces = Helpers.parse_namespace_filter(filter) end |
#enabled_for?(namespace) ⇒ Boolean
Decides whether namespace
is enabled on this device
157 158 159 160 |
# 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) ⇒ NilClass Also known as: <<
Log a message
to output device, within a namespace
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/lug/logger.rb', line 130 def log(, namespace = nil) line = [ Time.now, $$, namespace && "[#{namespace}]", ].compact.join(' '.freeze) @io.write("#{line}\n") nil end |
#on(namespace) ⇒ Lug::Logger
Clone logger with the same device and namespace
appended
148 149 150 |
# File 'lib/lug/logger.rb', line 148 def on(namespace) Logger.new(self, namespace) end |