context_logger 0.0.38 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4adde5696ccb1cee04e4f090b341a5cff7735e3d
|
|
4
|
+
data.tar.gz: a44ee6163026d37cfff05d27f51cabf999d8cdf7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f373ef4c2339c1d340e331f595f57bbae7c0c64b0cf6f5ad076f870716808a9506a3f7b4506f05947127542fec5dcbb12900b3ec4f42749ff5e46b02151467e4
|
|
7
|
+
data.tar.gz: 2e338e74825a0a9b4465c0cdca911687bb2e51e06c67543544b85bfdece6f8a67e73ea28afeba7fff893709b7699e4138e4f2e55b74c34ad3b7246cbcca655fb
|
|
@@ -8,11 +8,11 @@ class CreateContextLogs < ActiveRecord::Migration
|
|
|
8
8
|
t.string :server
|
|
9
9
|
t.string :action_id
|
|
10
10
|
t.string :method
|
|
11
|
-
t.
|
|
11
|
+
t.text :params
|
|
12
12
|
t.text :message
|
|
13
13
|
t.text :stack_trace
|
|
14
14
|
|
|
15
|
-
t.
|
|
15
|
+
t.column :created_at, :datetime
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
data/lib/context_logger.rb
CHANGED
|
@@ -2,7 +2,8 @@ require 'context_logger/engine'
|
|
|
2
2
|
|
|
3
3
|
module ContextLogger
|
|
4
4
|
|
|
5
|
-
SEVERITY_TYPES = [:info, :warn, :error, :debug, :
|
|
5
|
+
SEVERITY_TYPES = [:info, :warn, :error, :debug, :fatal, #:unknown
|
|
6
|
+
]
|
|
6
7
|
|
|
7
8
|
DEFAULTS = {
|
|
8
9
|
context: :context_log,
|
|
@@ -10,26 +11,29 @@ module ContextLogger
|
|
|
10
11
|
# server_name: nil,
|
|
11
12
|
# method: nil,
|
|
12
13
|
# params: nil,
|
|
13
|
-
message: 'Empty message',
|
|
14
|
+
# message: 'Empty message',
|
|
14
15
|
# stack_trace: nil
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
ALL_DESTINATIONS = {
|
|
19
|
+
write_rails_log: true,
|
|
20
|
+
write_context_log: true,
|
|
21
|
+
write_db_log: true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@options = DEFAULTS.clone
|
|
18
25
|
|
|
26
|
+
# build dynamically log methods for each of the SEVERITY_TYPES
|
|
19
27
|
SEVERITY_TYPES.each do |severity_type|
|
|
20
28
|
define_singleton_method severity_type do |message, method, params, stack_trace=nil, action_id=nil, context=nil ,server=nil|
|
|
21
29
|
self.log({severity: severity_type, context: context, server: server, action_id: action_id, method: method, params: params, message: message, stack_trace: stack_trace})
|
|
22
30
|
end
|
|
23
31
|
end
|
|
24
32
|
|
|
33
|
+
# hash (caching) of loggers by context
|
|
25
34
|
@context_loggers = {}
|
|
26
35
|
|
|
27
36
|
@destinations = {}
|
|
28
|
-
ALL_DESTINATIONS = {
|
|
29
|
-
write_rails_log: true,
|
|
30
|
-
write_context_log: true,
|
|
31
|
-
write_db_log: true
|
|
32
|
-
}
|
|
33
37
|
|
|
34
38
|
def self.setup(options)
|
|
35
39
|
@options = (@options || {}).merge(options)
|
|
@@ -45,7 +49,7 @@ module ContextLogger
|
|
|
45
49
|
return
|
|
46
50
|
end
|
|
47
51
|
|
|
48
|
-
@destinations = _destinations.select{|k,
|
|
52
|
+
@destinations = _destinations.select{|k, v| ALL_DESTINATIONS[k] and v}
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def self.destinations
|
|
@@ -67,8 +71,8 @@ module ContextLogger
|
|
|
67
71
|
def self.log(params)
|
|
68
72
|
params_with_defaults = options.merge(params.reject{|_, v| v.nil?})
|
|
69
73
|
|
|
70
|
-
destinations.each do |log_destination,
|
|
71
|
-
self.send(log_destination, params_with_defaults)
|
|
74
|
+
destinations.each do |log_destination, _|
|
|
75
|
+
self.send(log_destination, params_with_defaults)
|
|
72
76
|
end
|
|
73
77
|
end
|
|
74
78
|
|