lumberyak 0.1.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 +7 -0
- data/lib/activesupport/taggedlogging/formatter.rb +64 -0
- data/lib/lograge/formatter/noformat.rb +14 -0
- data/lib/lumberyak.rb +62 -0
- data/lib/lumberyak/version.rb +4 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2542d62276a1c1c56ee45a5108a106063cabec72
|
4
|
+
data.tar.gz: 82a9624e5dfbc30b194c0f3629a4d3cec8f1a833
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5eb223c4d0ef4317ef1277d50b8ef3efeb500d0c803c6421e1b689eb1551508e6371811c6fdf1a7adb40801e83439e23895a57aa350ed87231c9f36c9cb03b61
|
7
|
+
data.tar.gz: f66379861291b2ca798ba869442dbe8dde0bf469f77f258243533a503e778a6be1d3bf2dbdc3146ec14e8ec6ebe9e62ad6ad424b86cec2a89018a690a4021a66
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
module ActiveSupport
|
3
|
+
module TaggedLogging
|
4
|
+
module Formatter # :nodoc:
|
5
|
+
# This method is invoked when a log event occurs.
|
6
|
+
def call(severity, timestamp, progname, message)
|
7
|
+
# This scheme of serializing text log messages into a json format is
|
8
|
+
# loosely based on the logstasher.log() method found here:
|
9
|
+
# https://github.com/shadabahmed/logstasher/blob/master/lib/logstasher.rb#L160
|
10
|
+
# The major difference is we use the TaggedLogging formater's tagging ability.
|
11
|
+
# As implemented, TaggedLogging expects the proc's it executes return a scalar
|
12
|
+
# value which it converts to a string wrapped with brackets. The resulting
|
13
|
+
# behavior is logs that take the form of:
|
14
|
+
# '[23432342] [234245] error parsing post request'
|
15
|
+
# We could have left that intact by say having a tags field in our json doc that
|
16
|
+
# points to our list of tags, but this lacks context. So what we've done is change
|
17
|
+
# the convention in our application.rb to have our callback procs return hashes
|
18
|
+
# instead of scalars. This way, we get the context by letting the proc provide keys
|
19
|
+
# that describe each value.
|
20
|
+
data = { 'level' => severity }
|
21
|
+
if message.is_a? StandardError
|
22
|
+
e = message
|
23
|
+
data['type'] = e.class.to_s
|
24
|
+
data['message'] = e.message
|
25
|
+
data['backtrace'] = clean_backtrace(e).join("\n ")
|
26
|
+
elsif message.respond_to?(:to_hash)
|
27
|
+
data.merge!(message.to_hash)
|
28
|
+
else
|
29
|
+
data['message'] = message
|
30
|
+
end
|
31
|
+
data['timestamp'] = timestamp.iso8601
|
32
|
+
|
33
|
+
data.merge!(user_defined_attributes)
|
34
|
+
|
35
|
+
super(severity, timestamp, progname, data.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_defined_attributes
|
39
|
+
attrs = {
|
40
|
+
"tags" => []
|
41
|
+
}
|
42
|
+
current_tags.each do |t|
|
43
|
+
if t.respond_to?(:to_hash)
|
44
|
+
attrs.merge!(t.to_hash)
|
45
|
+
else
|
46
|
+
attrs["tags"].push(t)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
attrs
|
50
|
+
end
|
51
|
+
|
52
|
+
# Taken from http://stackoverflow.com/a/237846
|
53
|
+
def clean_backtrace(exception)
|
54
|
+
if backtrace = exception.backtrace
|
55
|
+
if defined?(RAILS_ROOT)
|
56
|
+
backtrace.map { |line| line.sub RAILS_ROOT, '' }
|
57
|
+
else
|
58
|
+
backtrace
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# We don't want Log Rage to do any message formatting as our JSON
|
4
|
+
# encoding owns this step. Otherwise we end up with a json encoded
|
5
|
+
# message within a json blob.
|
6
|
+
module Lograge
|
7
|
+
module Formatters
|
8
|
+
class NoFormat
|
9
|
+
def call(data)
|
10
|
+
data
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/lumberyak.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require 'active_support'
|
3
|
+
require 'rails/railtie'
|
4
|
+
require 'lograge'
|
5
|
+
require 'lograge/railtie'
|
6
|
+
require 'lograge/formatter/noformat'
|
7
|
+
|
8
|
+
module LumberYak
|
9
|
+
module_function
|
10
|
+
|
11
|
+
mattr_accessor :application
|
12
|
+
|
13
|
+
def setup(app)
|
14
|
+
self.application = app
|
15
|
+
setup_logger
|
16
|
+
setup_lograge
|
17
|
+
setup_logtags
|
18
|
+
enable_json_logging
|
19
|
+
end
|
20
|
+
|
21
|
+
class LumberYakRailtie < ::Rails::Railtie
|
22
|
+
config.lumberyak = ActiveSupport::OrderedOptions.new
|
23
|
+
config.lumberyak.enabled = false
|
24
|
+
config.lumberyak.configure_lograge = true
|
25
|
+
config.lumberyak.log_tags = nil
|
26
|
+
|
27
|
+
config.after_initialize do |app|
|
28
|
+
LumberYak.setup(app) if app.config.lumberyak.enabled
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup_logger
|
33
|
+
if application.config.logger
|
34
|
+
new_logger = ActiveSupport::TaggedLogging.new(application.config.logger)
|
35
|
+
application.config.logger = new_logger
|
36
|
+
Rails.logger = new_logger
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup_lograge
|
41
|
+
if config.configure_lograge
|
42
|
+
application.configure do
|
43
|
+
config.lograge.enabled = true
|
44
|
+
config.lograge.formatter = Lograge::Formatters::NoFormat.new
|
45
|
+
end
|
46
|
+
Lograge.setup(application)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup_logtags
|
51
|
+
application.config.log_tags = config.log_tags if config.log_tags
|
52
|
+
end
|
53
|
+
|
54
|
+
def enable_json_logging
|
55
|
+
# Explicitly require our monkey patch to ensure it takes effect.
|
56
|
+
require 'activesupport/taggedlogging/formatter.rb'
|
57
|
+
end
|
58
|
+
|
59
|
+
def config
|
60
|
+
application.config.lumberyak
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lumberyak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Roddy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.43.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.43.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: lograge
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '5.1'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '4'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.1'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: actionpack
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4'
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '5.1'
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '4'
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '5.1'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: railties
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '4'
|
102
|
+
- - "<"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '5.1'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '4'
|
112
|
+
- - "<"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '5.1'
|
115
|
+
description: LumberYak enables structured logging via JSON for any Rails application
|
116
|
+
email:
|
117
|
+
- mroddy@primary.com
|
118
|
+
executables: []
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- lib/activesupport/taggedlogging/formatter.rb
|
123
|
+
- lib/lograge/formatter/noformat.rb
|
124
|
+
- lib/lumberyak.rb
|
125
|
+
- lib/lumberyak/version.rb
|
126
|
+
homepage: https://github.com/PrimaryKids/lumberyak
|
127
|
+
licenses:
|
128
|
+
- Apache
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.4.5.1
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Structured Logging for Rails Applications
|
150
|
+
test_files: []
|