chihiro 0.2.2 → 0.3.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/chihiro/initializer.rb +5 -5
- data/lib/chihiro/json_log_formatter.rb +2 -2
- data/lib/chihiro/loggable.rb +52 -0
- data/lib/chihiro/version.rb +1 -1
- data/lib/chihiro.rb +1 -0
- data/pkg/chihiro-0.2.2.gem +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19a0c1588e96239af86932d782fde853c350ed8ddb7eee1d878a00551e0ed96a
|
4
|
+
data.tar.gz: 7c38262b300d98a138bb51e833a71da78eedfd6e03e83aba157aac974bb48c8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4e36a40c4c9d4e40749664808efa5419660a5573804ff27e35751dbcda02a14d1a214ce55c72c5f33962309d7ad19287d9882efa615eeb1ed4218473f406d98
|
7
|
+
data.tar.gz: 3394d08f54bcbb7cba1dbde34f22a611317d8f5585708114ea2e46fe35424221477e27bac6f7bf5ee443f9e287ee9040ef843958d7a0b37222fa16ffa18bf13a
|
data/Gemfile.lock
CHANGED
data/lib/chihiro/initializer.rb
CHANGED
@@ -16,11 +16,11 @@ module Chihiro
|
|
16
16
|
config.lograge.enabled = true
|
17
17
|
config.lograge.base_controller_class = 'ActionController::API'
|
18
18
|
config.lograge.ignore_actions = ['HealthCheckController#index']
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
|
20
|
+
logger = ActiveSupport::Logger.new(STDOUT)
|
21
|
+
logger.formatter = config.log_formatter
|
22
|
+
config.logger = logger
|
23
|
+
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Chihiro
|
4
|
-
class JsonLogFormatter < Logger::Formatter
|
4
|
+
class JsonLogFormatter < ::Logger::Formatter
|
5
5
|
def call(severity, _time, _progname, msg)
|
6
6
|
extra_log_data(msg).merge(
|
7
7
|
level: severity.downcase,
|
@@ -16,7 +16,7 @@ module Chihiro
|
|
16
16
|
|
17
17
|
def extra_log_data(msg)
|
18
18
|
if msg.is_a? Hash
|
19
|
-
msg
|
19
|
+
MaskUtil.mask(msg)
|
20
20
|
elsif msg.is_a? Exception
|
21
21
|
{ message: msg.message, backtrace: msg.backtrace }
|
22
22
|
else
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Chihiro
|
2
|
+
module Loggable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
around_action :log_and_deal_exceptions
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def log_and_deal_exceptions
|
12
|
+
log_request
|
13
|
+
yield
|
14
|
+
log_response
|
15
|
+
rescue => e
|
16
|
+
log_exception(e)
|
17
|
+
raise
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_request
|
21
|
+
to_log = {
|
22
|
+
message: 'Received API request',
|
23
|
+
requestPath: request.path
|
24
|
+
}
|
25
|
+
if Rails.configuration.no_log_param_paths.include?("#{controller_name}##{action_name}")
|
26
|
+
Rails.logger.info(to_log)
|
27
|
+
else
|
28
|
+
Rails.logger.info(to_log.merge(params: params.as_json))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def log_response
|
33
|
+
to_log = {
|
34
|
+
message: 'Send API Response',
|
35
|
+
requestPath: request.path,
|
36
|
+
responseStatus: response.status.to_s
|
37
|
+
}
|
38
|
+
Rails.logger.info(to_log)
|
39
|
+
end
|
40
|
+
|
41
|
+
def log_exception(e)
|
42
|
+
to_log = {
|
43
|
+
message: 'Catched exception in controller',
|
44
|
+
requestPath: request.path,
|
45
|
+
exceptionClass: e.class.to_s,
|
46
|
+
exceptionMessage: e.message,
|
47
|
+
backtrace: e.backtrace
|
48
|
+
}
|
49
|
+
Rails.logger.error(to_log)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/chihiro/version.rb
CHANGED
data/lib/chihiro.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chihiro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shu Hui
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/chihiro.rb
|
100
100
|
- lib/chihiro/initializer.rb
|
101
101
|
- lib/chihiro/json_log_formatter.rb
|
102
|
+
- lib/chihiro/loggable.rb
|
102
103
|
- lib/chihiro/mask_util.rb
|
103
104
|
- lib/chihiro/version.rb
|
104
105
|
- lib/generators/chihiro/init_generator.rb
|
@@ -108,6 +109,7 @@ files:
|
|
108
109
|
- pkg/chihiro-0.1.9.gem
|
109
110
|
- pkg/chihiro-0.2.0.gem
|
110
111
|
- pkg/chihiro-0.2.1.gem
|
112
|
+
- pkg/chihiro-0.2.2.gem
|
111
113
|
- spec/chihiro_spec.rb
|
112
114
|
- spec/mask_util_spec.rb
|
113
115
|
- spec/spec_helper.rb
|