Class: RailsGraylogger::Logger
- Inherits:
-
Object
- Object
- RailsGraylogger::Logger
show all
- Defined in:
- lib/rails-graylogger/logger.rb
Constant Summary
collapse
- FIELD_KEY_REGEXP =
/^[\w\.\-]*$/
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(logger) ⇒ Logger
Returns a new instance of Logger.
5
6
7
|
# File 'lib/rails-graylogger/logger.rb', line 5
def initialize(logger)
@logger = logger
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/rails-graylogger/logger.rb', line 31
def method_missing(method, *args, &block)
if [:add, :info, :debug, :warn, :error, :fatal].include?(method) && !args[0].nil?
if args.size == 1 && args[0].is_a?(String)
hash = { short_message: args[0] }
else
return if args.blank?
hash = { short_message: args.compact.map(&:to_s).join("\n") }
end
unless self.class.request_buffer.nil?
self.class.request_buffer << hash
else
notify!(method, hash)
end
end
@logger.send(method, *args, &block)
end
|
Class Method Details
.initialize_log_buffer ⇒ Object
10
11
12
|
# File 'lib/rails-graylogger/logger.rb', line 10
def initialize_log_buffer
RequestStore.store[:graylog2_buffer] = []
end
|
.request_buffer ⇒ Object
18
19
20
|
# File 'lib/rails-graylogger/logger.rb', line 18
def request_buffer
RequestStore.store[:graylog2_buffer]
end
|
14
15
16
|
# File 'lib/rails-graylogger/logger.rb', line 14
def request_tags
RequestStore.store[:graylog2_tags] ||= []
end
|
Instance Method Details
#tagged(*new_tags, &block) ⇒ Object
23
24
25
26
27
|
# File 'lib/rails-graylogger/logger.rb', line 23
def tagged(*new_tags, &block)
new_tags = Array.wrap(new_tags).flatten.reject(&:blank?)
self.class.request_tags << new_tags - ( self.class.request_tags & new_tags )
@logger.send("tagged", *new_tags, &block)
end
|