Module: Loggerator
- Included in:
- Metrics, Namespace, Railtie::LogSubscriber
- Defined in:
- lib/loggerator/log.rb,
lib/loggerator/test.rb,
lib/loggerator/rails.rb,
lib/loggerator/metrics.rb,
lib/loggerator/namespace.rb,
lib/loggerator/loggerator.rb,
lib/loggerator/middleware.rb,
lib/loggerator/configuration.rb,
lib/loggerator/request_store.rb,
lib/loggerator/railtie/helper.rb,
lib/loggerator/railtie/adapter.rb,
lib/loggerator/railtie/log_subscriber.rb,
lib/generators/loggerator/log_generator.rb
Defined Under Namespace
Modules: Log, Metrics, Middleware, Namespace, Railtie, RequestStore
Classes: Configuration, LogGenerator
Constant Summary
collapse
- @@log_switch =
true
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.config {|@config| ... } ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/loggerator/loggerator.rb', line 11
def self.config
@config ||= Configuration.new
return @config unless block_given?
yield(@config)
end
|
.config=(cfg) ⇒ Object
19
20
21
|
# File 'lib/loggerator/loggerator.rb', line 19
def self.config=(cfg)
@config = Configuration.new(cfg)
end
|
.included(mod) ⇒ Object
7
8
9
|
# File 'lib/loggerator/loggerator.rb', line 7
def self.included(mod)
mod.extend self
end
|
.log? ⇒ Boolean
23
24
25
|
# File 'lib/loggerator/test.rb', line 23
def log?
@@log_switch
end
|
.turn_log(on_or_off) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/loggerator/test.rb', line 16
def turn_log(on_or_off)
return unless %i[on off].include?(on_or_off.to_sym)
alias_method :log, :"log_#{on_or_off}"
alias_method :log_error, :"log_error_#{on_or_off}"
@@log_switch = on_or_off.to_sym == :on
end
|
Instance Method Details
#log(data, &block) ⇒ Object
#log_context(data, &block) ⇒ Object
#log_error(error, data = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/loggerator/loggerator.rb', line 27
def log_error(error, data = {})
exception_id = error.object_id
if error.backtrace
error.backtrace.reverse.each do |backtrace|
Log.to_stream(Log.stderr, Log.contexts(
exception_id: exception_id,
backtrace: backtrace
))
end
end
data.merge!(
exception: true,
class: error.class.name,
message: error.message,
exception_id: exception_id
)
data[:status] = error.status if error.respond_to?(:status)
Log.to_stream(Log.stderr, Log.contexts(data))
end
|
#log_error_off(e, data = {}, &block) ⇒ Object
9
10
11
|
# File 'lib/loggerator/test.rb', line 9
def log_error_off(e, data={}, &block)
block.call if block
end
|
#log_error_on ⇒ Object
3
|
# File 'lib/loggerator/test.rb', line 3
alias_method :log_error_on, :log_error
|
#log_off(data, &block) ⇒ Object
5
6
7
|
# File 'lib/loggerator/test.rb', line 5
def log_off(data, &block)
block.call if block
end
|
#log_on ⇒ Object
2
|
# File 'lib/loggerator/test.rb', line 2
alias_method :log_on, :log
|
#m ⇒ Object
included Metrics shortcut
26
|
# File 'lib/loggerator/metrics.rb', line 26
def m; Metrics; end
|