gray_logger 0.9.5 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +35 -5
- data/lib/gray_logger/logger.rb +13 -1
- data/lib/gray_logger/rack.rb +9 -5
- metadata +4 -4
data/README.md
CHANGED
@@ -34,15 +34,45 @@ GrayLogger is a small logging tool that allows you to simply log anything you wa
|
|
34
34
|
ActionController::Base.send(:include, ::GrayLogger::HelperMethods)
|
35
35
|
````
|
36
36
|
|
37
|
+
4. To install the gray_logger proxy:
|
38
|
+
````ruby
|
39
|
+
config.logger = Rack::GrayLogger::Proxy.new(Syslogger.new("path..."))
|
40
|
+
````
|
41
|
+
|
37
42
|
## Usage
|
38
43
|
|
39
44
|
In Rails you can use the "gray_logger" method to add new fields to be logged to Graylog2.
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
#### Buckets
|
47
|
+
You can use buckets to collect fields and send them in one request to GrayLog2:
|
48
|
+
|
49
|
+
````ruby
|
50
|
+
gray_logger.bucket(:financial_data).account_nr = 123
|
51
|
+
gray_logger.bucket(:financial_data).iban = 98767
|
52
|
+
gray_logger.flush_bucket(:financial_data) # sends the collected fields as one log message to GrayLog2 and clears the bucket
|
53
|
+
````
|
54
|
+
When the request is finished all remaining buckets are send to GrayLog2 so you don't have to care if you only want to collect your data.
|
55
|
+
|
56
|
+
#### After Request Log
|
57
|
+
|
58
|
+
There is a special bucket that is used for logging possible exceptions and request information.
|
59
|
+
When you are using the Rack::GrayLogger::Proxy the proxy will use this bucket to collect the loglines
|
60
|
+
from the proxied logger. Feel free to add your own fields using:
|
61
|
+
|
62
|
+
````ruby
|
63
|
+
gray_logger.after_request_log.user_login = current_user.login
|
64
|
+
````
|
65
|
+
|
66
|
+
#### Automatic Logging
|
45
67
|
|
46
|
-
|
68
|
+
Automatic Logging is enabled by default. That means after the request is done GrayLogger will automatically
|
69
|
+
log to GrayLog2. If you don't want this automatic logging disable it by setting automatic_logging to false.
|
47
70
|
|
71
|
+
````yaml
|
72
|
+
development:
|
73
|
+
host: ...
|
74
|
+
port: ...
|
75
|
+
facility: ...
|
76
|
+
automatic_logging: false
|
77
|
+
````
|
48
78
|
|
data/lib/gray_logger/logger.rb
CHANGED
@@ -2,9 +2,12 @@ module GrayLogger
|
|
2
2
|
|
3
3
|
class Logger < GELF::Logger
|
4
4
|
include ::GrayLogger::Support
|
5
|
-
attr_reader :buckets
|
5
|
+
attr_reader :buckets, :automatic_logging
|
6
6
|
|
7
7
|
def initialize(configuration={})
|
8
|
+
automatic_logging = configuration.delete(:automatic_logging)
|
9
|
+
@automatic_logging = automatic_logging.nil? ? true : automatic_logging
|
10
|
+
|
8
11
|
defaults = {
|
9
12
|
:size => "WAN",
|
10
13
|
:facility => "facility-not-defined"
|
@@ -18,6 +21,15 @@ module GrayLogger
|
|
18
21
|
@buckets = {}
|
19
22
|
end
|
20
23
|
|
24
|
+
def automatic_logging?
|
25
|
+
!!@automatic_logging
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset!
|
29
|
+
@buckets = {}
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
21
33
|
# logger.after_request_log << {:my_field => 'field content'}
|
22
34
|
# logger.after_request_log.my_field = 'field content'
|
23
35
|
def after_request_log
|
data/lib/gray_logger/rack.rb
CHANGED
@@ -19,14 +19,18 @@ module Rack
|
|
19
19
|
begin
|
20
20
|
status, headers, body = @app.call(env)
|
21
21
|
rescue => e
|
22
|
-
gray_logger.log_exception(e)
|
22
|
+
gray_logger.log_exception(e) if gray_logger.automatic_logging?
|
23
23
|
raise
|
24
24
|
ensure
|
25
25
|
req = Rack::Request.new(env)
|
26
|
-
gray_logger.
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
if gray_logger.automatic_logging?
|
27
|
+
gray_logger.log_exception(env['rack.exception'])
|
28
|
+
gray_logger.after_request_log.status_code = status.to_i
|
29
|
+
gray_logger.after_request_log.short_message = "Request: #{req.path} (#{status.to_i})" if gray_logger.after_request_log[:short_message].nil?
|
30
|
+
gray_logger.flush
|
31
|
+
else
|
32
|
+
gray_logger.reset!
|
33
|
+
end
|
30
34
|
[status, headers, body]
|
31
35
|
end
|
32
36
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gray_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 10
|
9
|
+
- 0
|
10
|
+
version: 0.10.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Behr
|