Class: Flnt::Logger
- Inherits:
-
Object
show all
- Defined in:
- lib/flnt/logger.rb
Instance Method Summary
collapse
Constructor Details
#initialize(init_tag) ⇒ Logger
Returns a new instance of Logger.
21
22
23
|
# File 'lib/flnt/logger.rb', line 21
def initialize(init_tag)
@tag = init_tag
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/flnt/logger.rb', line 25
def method_missing(name, *args)
return super if name.to_s =~ /(!|\?)$/
if !args.empty?
emit! args.first, tag: [@tag, name.to_s].join('.')
else
@tag << "." << name.to_s
end
return self
end
|
Instance Method Details
#emit!(arg, tag: nil) ⇒ Object
50
51
52
|
# File 'lib/flnt/logger.rb', line 50
def emit!(arg, tag: nil)
::Fluent::Logger.post((tag || @tag), to_info!(arg))
end
|
#tee!(logger_or_path) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/flnt/logger.rb', line 54
def tee!(logger_or_path)
new_self = TeeableLogger.new(@tag)
case
when logger_or_path.respond_to?(:info)
new_self.teed_logger = logger_or_path
when [::String, ::Pathname].include?(logger_or_path.class)
l = ::Logger.new(logger_or_path)
new_self.teed_logger = l
end
new_self
end
|