grape_logging 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59face7f1f95aa107acdf703dbc1f3b7cd7a7089
4
- data.tar.gz: ddbc3faa4075116e49201ed0e42a8a484fe6f0bb
3
+ metadata.gz: fe992e3b160e737c3ad0d38a636252db026dbf97
4
+ data.tar.gz: fbbcd347c5846b25d4a737a964fb2600c4e8ac98
5
5
  SHA512:
6
- metadata.gz: 80f4eea80aa5b7cdee7e6e2f45ec1a52c35c41839f67988fa89a70290b6706547cc4a664cce4a0dea136fd5d56b6bc266e8d592176b732e94527c8731c038219
7
- data.tar.gz: 6effcdf54c98000c0b8417ea2f02c6a707054ade7e66c035cc55e68ee721d5d25cf9d81c34683545f1a31c88d8bc6a433219600164369078294c3b48fc92b8ed
6
+ metadata.gz: 35efe1809d92fa3a12d260f71306b8c2aa8f08254607ea2c46c9d3c2dcc38e5a8a009af0b4044f26660feae420b12ef5c0f4d17059d086227253cc2cc9a16000
7
+ data.tar.gz: a2021c9a92c8b4c4d96cf494b3ef27da4c17bb05c839d7c8e3c35660fbfbae9ba279380f66c173c7e863d110de7c959207367f180292258c3f218f1a72c6272e
data/README.md CHANGED
@@ -19,7 +19,7 @@ Or install it yourself as:
19
19
  ## Basic Usage
20
20
 
21
21
  In your api file (somewhere on the top)
22
-
22
+
23
23
  require 'grape_logging'
24
24
  logger.formatter = GrapeLogging::Formatters::Default.new
25
25
  use GrapeLogging::Middleware::RequestLogger, { logger: logger }
@@ -50,19 +50,28 @@ You can include logging of other parts of the request / response cycle by includ
50
50
  use GrapeLogging::Middleware::RequestLogger,
51
51
  logger: logger,
52
52
  include: [ GrapeLogging::Loggers::Response.new,
53
- GrapeLogging::Loggers::FilterParameters.new ]
53
+ GrapeLogging::Loggers::FilterParameters.new,
54
+ GrapeLogging::Loggers::ClientEnv.new,
55
+ GrapeLogging::Loggers::RequestHeaders.new ]
54
56
  end
55
57
 
58
+ #### FilterParameters
56
59
  The `FilterParameters` logger will filter out sensitive parameters from your logs. If mounted inside rails, will use the `Rails.application.config.filter_parameters` by default. Otherwise, you must specify a list of keys to filter out.
57
60
 
61
+ #### ClientEnv
62
+ The `ClientEnv` logger will add `ip` and user agent `ua` in your log.
63
+
64
+ #### RequestHeaders
65
+ The `RequestHeaders` logger will add `request headers` in your log.
66
+
58
67
  ### Logging to file and STDOUT
59
68
 
60
69
  You can log to file and STDOUT at the same time, you just need to assign new logger
61
-
70
+
62
71
  log_file = File.open('path/to/your/logfile.log', 'a')
63
72
  log_file.sync = true
64
73
  logger Logger.new GrapeLogging::MultiIO.new(STDOUT, log_file)
65
-
74
+
66
75
  ### Logging via Rails instrumentation
67
76
 
68
77
  You can choose to not pass the logger to ```grape_logging``` but instead send logs to Rails instrumentation in order to let Rails and its configured Logger do the log job, for example.
@@ -74,16 +83,16 @@ First, config ```grape_logging```, like that:
74
83
  include: [ GrapeLogging::Loggers::Response.new,
75
84
  GrapeLogging::Loggers::FilterParameters.new ]
76
85
  end
77
-
86
+
78
87
  and then add an initializer in your Rails project:
79
-
88
+
80
89
  # config/initializers/instrumentation.rb
81
-
90
+
82
91
  # Subscribe to grape request and log with Rails.logger
83
92
  ActiveSupport::Notifications.subscribe('grape_key') do |name, starts, ends, notification_id, payload|
84
93
  Rails.logger.info payload
85
94
  end
86
-
95
+
87
96
  The idea come from here: https://gist.github.com/teamon/e8ae16ffb0cb447e5b49
88
97
 
89
98
  ### Logging exceptions
data/lib/grape_logging.rb CHANGED
@@ -5,6 +5,8 @@ require 'grape_logging/formatters/json'
5
5
  require 'grape_logging/loggers/base'
6
6
  require 'grape_logging/loggers/response'
7
7
  require 'grape_logging/loggers/filter_parameters'
8
+ require 'grape_logging/loggers/client_env'
9
+ require 'grape_logging/loggers/request_headers'
8
10
  require 'grape_logging/reporters/active_support_reporter'
9
11
  require 'grape_logging/reporters/logger_reporter'
10
12
  require 'grape_logging/timings'
@@ -0,0 +1,9 @@
1
+ module GrapeLogging
2
+ module Loggers
3
+ class ClientEnv < GrapeLogging::Loggers::Base
4
+ def parameters(request, _)
5
+ { ip: request.env["HTTP_X_FORWARDED_FOR"] || request.env["REMOTE_ADDR"], ua: request.env["HTTP_USER_AGENT"] }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module GrapeLogging
2
+ module Loggers
3
+ class RequestHeaders < GrapeLogging::Loggers::Base
4
+
5
+ HTTP_PREFIX = 'HTTP_'.freeze
6
+
7
+ def parameters(request, _)
8
+ headers = {}
9
+
10
+ request.env.each_pair do |k, v|
11
+ next unless k.to_s.start_with? HTTP_PREFIX
12
+
13
+ k = k[5..-1].split('_').each(&:capitalize!).join('-')
14
+ headers[k] = v
15
+ end
16
+
17
+ { headers: headers }
18
+ end
19
+
20
+
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module GrapeLogging
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aserafin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -73,7 +73,9 @@ files:
73
73
  - lib/grape_logging/formatters/default.rb
74
74
  - lib/grape_logging/formatters/json.rb
75
75
  - lib/grape_logging/loggers/base.rb
76
+ - lib/grape_logging/loggers/client_env.rb
76
77
  - lib/grape_logging/loggers/filter_parameters.rb
78
+ - lib/grape_logging/loggers/request_headers.rb
77
79
  - lib/grape_logging/loggers/response.rb
78
80
  - lib/grape_logging/middleware/request_logger.rb
79
81
  - lib/grape_logging/multi_io.rb