mr_loga_loga 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -0
- data/.github/workflows/main.yml +0 -1
- data/.github/workflows/release.yml +79 -0
- data/.gitignore +1 -0
- data/.tool-versions +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile.lock +7 -5
- data/README.md +12 -8
- data/docs/MrLogaLoga/Configuration.html +376 -0
- data/docs/MrLogaLoga/Context.html +628 -0
- data/docs/MrLogaLoga/Error.html +124 -0
- data/docs/MrLogaLoga/Extensions/LogrageExtension.html +305 -0
- data/docs/MrLogaLoga/Extensions/RailsExtension/LoggerPatch.html +322 -0
- data/docs/MrLogaLoga/Extensions/RailsExtension/ServerPatch.html +201 -0
- data/docs/MrLogaLoga/Extensions/RailsExtension.html +242 -0
- data/docs/MrLogaLoga/Extensions.html +117 -0
- data/docs/MrLogaLoga/Formatters/Json.html +350 -0
- data/docs/MrLogaLoga/Formatters/KeyValue.html +338 -0
- data/docs/MrLogaLoga/Formatters.html +117 -0
- data/docs/MrLogaLoga/InstanceMethods.html +350 -0
- data/docs/MrLogaLoga/Logger.html +618 -0
- data/docs/MrLogaLoga/LoggerProxy.html +319 -0
- data/docs/MrLogaLoga.html +374 -0
- data/docs/_config.yml +1 -0
- data/docs/_index.html +280 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +255 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +255 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +283 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/mr_loga_loga/context.rb +10 -0
- data/lib/mr_loga_loga/extensions/{lograge_patch.rb → lograge.rb} +19 -8
- data/lib/mr_loga_loga/extensions/rails.rb +142 -0
- data/lib/mr_loga_loga/formatters/json.rb +4 -4
- data/lib/mr_loga_loga/formatters/key_value.rb +2 -1
- data/lib/mr_loga_loga/instance_methods.rb +9 -3
- data/lib/mr_loga_loga/logger.rb +23 -14
- data/lib/mr_loga_loga/logger_proxy.rb +9 -8
- data/lib/mr_loga_loga/version.rb +1 -1
- data/lib/mr_loga_loga.rb +3 -4
- data/mr_loga_loga.gemspec +4 -4
- metadata +57 -22
@@ -0,0 +1,283 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>Method List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">Method List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="method">
|
45
|
+
|
46
|
+
|
47
|
+
<li class="odd ">
|
48
|
+
<div class="item">
|
49
|
+
<span class='object_link'><a href="MrLogaLoga/Logger.html#add-instance_method" title="MrLogaLoga::Logger#add (method)">#add</a></span>
|
50
|
+
<small>MrLogaLoga::Logger</small>
|
51
|
+
</div>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
|
55
|
+
<li class="even ">
|
56
|
+
<div class="item">
|
57
|
+
<span class='object_link'><a href="MrLogaLoga/Context.html#add-instance_method" title="MrLogaLoga::Context#add (method)">#add</a></span>
|
58
|
+
<small>MrLogaLoga::Context</small>
|
59
|
+
</div>
|
60
|
+
</li>
|
61
|
+
|
62
|
+
|
63
|
+
<li class="odd ">
|
64
|
+
<div class="item">
|
65
|
+
<span class='object_link'><a href="MrLogaLoga/LoggerProxy.html#add-instance_method" title="MrLogaLoga::LoggerProxy#add (method)">#add</a></span>
|
66
|
+
<small>MrLogaLoga::LoggerProxy</small>
|
67
|
+
</div>
|
68
|
+
</li>
|
69
|
+
|
70
|
+
|
71
|
+
<li class="even ">
|
72
|
+
<div class="item">
|
73
|
+
<span class='object_link'><a href="MrLogaLoga/Extensions/RailsExtension.html#apply-class_method" title="MrLogaLoga::Extensions::RailsExtension.apply (method)">apply</a></span>
|
74
|
+
<small>MrLogaLoga::Extensions::RailsExtension</small>
|
75
|
+
</div>
|
76
|
+
</li>
|
77
|
+
|
78
|
+
|
79
|
+
<li class="odd ">
|
80
|
+
<div class="item">
|
81
|
+
<span class='object_link'><a href="MrLogaLoga/Extensions/LogrageExtension.html#apply-class_method" title="MrLogaLoga::Extensions::LogrageExtension.apply (method)">apply</a></span>
|
82
|
+
<small>MrLogaLoga::Extensions::LogrageExtension</small>
|
83
|
+
</div>
|
84
|
+
</li>
|
85
|
+
|
86
|
+
|
87
|
+
<li class="even ">
|
88
|
+
<div class="item">
|
89
|
+
<span class='object_link'><a href="MrLogaLoga/Formatters/Json.html#call-instance_method" title="MrLogaLoga::Formatters::Json#call (method)">#call</a></span>
|
90
|
+
<small>MrLogaLoga::Formatters::Json</small>
|
91
|
+
</div>
|
92
|
+
</li>
|
93
|
+
|
94
|
+
|
95
|
+
<li class="odd ">
|
96
|
+
<div class="item">
|
97
|
+
<span class='object_link'><a href="MrLogaLoga/Formatters/KeyValue.html#call-instance_method" title="MrLogaLoga::Formatters::KeyValue#call (method)">#call</a></span>
|
98
|
+
<small>MrLogaLoga::Formatters::KeyValue</small>
|
99
|
+
</div>
|
100
|
+
</li>
|
101
|
+
|
102
|
+
|
103
|
+
<li class="even ">
|
104
|
+
<div class="item">
|
105
|
+
<span class='object_link'><a href="MrLogaLoga.html#configuration-class_method" title="MrLogaLoga.configuration (method)">configuration</a></span>
|
106
|
+
<small>MrLogaLoga</small>
|
107
|
+
</div>
|
108
|
+
</li>
|
109
|
+
|
110
|
+
|
111
|
+
<li class="odd ">
|
112
|
+
<div class="item">
|
113
|
+
<span class='object_link'><a href="MrLogaLoga.html#configure-class_method" title="MrLogaLoga.configure (method)">configure</a></span>
|
114
|
+
<small>MrLogaLoga</small>
|
115
|
+
</div>
|
116
|
+
</li>
|
117
|
+
|
118
|
+
|
119
|
+
<li class="even ">
|
120
|
+
<div class="item">
|
121
|
+
<span class='object_link'><a href="MrLogaLoga/Logger.html#context-instance_method" title="MrLogaLoga::Logger#context (method)">#context</a></span>
|
122
|
+
<small>MrLogaLoga::Logger</small>
|
123
|
+
</div>
|
124
|
+
</li>
|
125
|
+
|
126
|
+
|
127
|
+
<li class="odd ">
|
128
|
+
<div class="item">
|
129
|
+
<span class='object_link'><a href="MrLogaLoga/Context.html#context-instance_method" title="MrLogaLoga::Context#context (method)">#context</a></span>
|
130
|
+
<small>MrLogaLoga::Context</small>
|
131
|
+
</div>
|
132
|
+
</li>
|
133
|
+
|
134
|
+
|
135
|
+
<li class="even ">
|
136
|
+
<div class="item">
|
137
|
+
<span class='object_link'><a href="MrLogaLoga.html#included-class_method" title="MrLogaLoga.included (method)">included</a></span>
|
138
|
+
<small>MrLogaLoga</small>
|
139
|
+
</div>
|
140
|
+
</li>
|
141
|
+
|
142
|
+
|
143
|
+
<li class="odd ">
|
144
|
+
<div class="item">
|
145
|
+
<span class='object_link'><a href="MrLogaLoga/Extensions/RailsExtension/LoggerPatch.html#included-instance_method" title="MrLogaLoga::Extensions::RailsExtension::LoggerPatch#included (method)">#included</a></span>
|
146
|
+
<small>MrLogaLoga::Extensions::RailsExtension::LoggerPatch</small>
|
147
|
+
</div>
|
148
|
+
</li>
|
149
|
+
|
150
|
+
|
151
|
+
<li class="even ">
|
152
|
+
<div class="item">
|
153
|
+
<span class='object_link'><a href="MrLogaLoga/Logger.html#initialize-instance_method" title="MrLogaLoga::Logger#initialize (method)">#initialize</a></span>
|
154
|
+
<small>MrLogaLoga::Logger</small>
|
155
|
+
</div>
|
156
|
+
</li>
|
157
|
+
|
158
|
+
|
159
|
+
<li class="odd ">
|
160
|
+
<div class="item">
|
161
|
+
<span class='object_link'><a href="MrLogaLoga/Context.html#initialize-instance_method" title="MrLogaLoga::Context#initialize (method)">#initialize</a></span>
|
162
|
+
<small>MrLogaLoga::Context</small>
|
163
|
+
</div>
|
164
|
+
</li>
|
165
|
+
|
166
|
+
|
167
|
+
<li class="even ">
|
168
|
+
<div class="item">
|
169
|
+
<span class='object_link'><a href="MrLogaLoga/LoggerProxy.html#initialize-instance_method" title="MrLogaLoga::LoggerProxy#initialize (method)">#initialize</a></span>
|
170
|
+
<small>MrLogaLoga::LoggerProxy</small>
|
171
|
+
</div>
|
172
|
+
</li>
|
173
|
+
|
174
|
+
|
175
|
+
<li class="odd ">
|
176
|
+
<div class="item">
|
177
|
+
<span class='object_link'><a href="MrLogaLoga/Configuration.html#initialize-instance_method" title="MrLogaLoga::Configuration#initialize (method)">#initialize</a></span>
|
178
|
+
<small>MrLogaLoga::Configuration</small>
|
179
|
+
</div>
|
180
|
+
</li>
|
181
|
+
|
182
|
+
|
183
|
+
<li class="even ">
|
184
|
+
<div class="item">
|
185
|
+
<span class='object_link'><a href="MrLogaLoga/Logger.html#log%3F-instance_method" title="MrLogaLoga::Logger#log? (method)">#log?</a></span>
|
186
|
+
<small>MrLogaLoga::Logger</small>
|
187
|
+
</div>
|
188
|
+
</li>
|
189
|
+
|
190
|
+
|
191
|
+
<li class="odd ">
|
192
|
+
<div class="item">
|
193
|
+
<span class='object_link'><a href="MrLogaLoga/Extensions/RailsExtension/ServerPatch.html#log_to_stdout-instance_method" title="MrLogaLoga::Extensions::RailsExtension::ServerPatch#log_to_stdout (method)">#log_to_stdout</a></span>
|
194
|
+
<small>MrLogaLoga::Extensions::RailsExtension::ServerPatch</small>
|
195
|
+
</div>
|
196
|
+
</li>
|
197
|
+
|
198
|
+
|
199
|
+
<li class="even ">
|
200
|
+
<div class="item">
|
201
|
+
<span class='object_link'><a href="MrLogaLoga/InstanceMethods.html#loga_context-instance_method" title="MrLogaLoga::InstanceMethods#loga_context (method)">#loga_context</a></span>
|
202
|
+
<small>MrLogaLoga::InstanceMethods</small>
|
203
|
+
</div>
|
204
|
+
</li>
|
205
|
+
|
206
|
+
|
207
|
+
<li class="odd ">
|
208
|
+
<div class="item">
|
209
|
+
<span class='object_link'><a href="MrLogaLoga/InstanceMethods.html#loga_loga-instance_method" title="MrLogaLoga::InstanceMethods#loga_loga (method)">#loga_loga</a></span>
|
210
|
+
<small>MrLogaLoga::InstanceMethods</small>
|
211
|
+
</div>
|
212
|
+
</li>
|
213
|
+
|
214
|
+
|
215
|
+
<li class="even ">
|
216
|
+
<div class="item">
|
217
|
+
<span class='object_link'><a href="MrLogaLoga/Configuration.html#logger-instance_method" title="MrLogaLoga::Configuration#logger (method)">#logger</a></span>
|
218
|
+
<small>MrLogaLoga::Configuration</small>
|
219
|
+
</div>
|
220
|
+
</li>
|
221
|
+
|
222
|
+
|
223
|
+
<li class="odd ">
|
224
|
+
<div class="item">
|
225
|
+
<span class='object_link'><a href="MrLogaLoga/InstanceMethods.html#logger-instance_method" title="MrLogaLoga::InstanceMethods#logger (method)">#logger</a></span>
|
226
|
+
<small>MrLogaLoga::InstanceMethods</small>
|
227
|
+
</div>
|
228
|
+
</li>
|
229
|
+
|
230
|
+
|
231
|
+
<li class="even ">
|
232
|
+
<div class="item">
|
233
|
+
<span class='object_link'><a href="MrLogaLoga/Logger.html#method_missing-instance_method" title="MrLogaLoga::Logger#method_missing (method)">#method_missing</a></span>
|
234
|
+
<small>MrLogaLoga::Logger</small>
|
235
|
+
</div>
|
236
|
+
</li>
|
237
|
+
|
238
|
+
|
239
|
+
<li class="odd ">
|
240
|
+
<div class="item">
|
241
|
+
<span class='object_link'><a href="MrLogaLoga/Context.html#method_missing-instance_method" title="MrLogaLoga::Context#method_missing (method)">#method_missing</a></span>
|
242
|
+
<small>MrLogaLoga::Context</small>
|
243
|
+
</div>
|
244
|
+
</li>
|
245
|
+
|
246
|
+
|
247
|
+
<li class="even ">
|
248
|
+
<div class="item">
|
249
|
+
<span class='object_link'><a href="MrLogaLoga/Extensions/LogrageExtension.html#process_main_event-instance_method" title="MrLogaLoga::Extensions::LogrageExtension#process_main_event (method)">#process_main_event</a></span>
|
250
|
+
<small>MrLogaLoga::Extensions::LogrageExtension</small>
|
251
|
+
</div>
|
252
|
+
</li>
|
253
|
+
|
254
|
+
|
255
|
+
<li class="odd ">
|
256
|
+
<div class="item">
|
257
|
+
<span class='object_link'><a href="MrLogaLoga/Configuration.html#reset-instance_method" title="MrLogaLoga::Configuration#reset (method)">#reset</a></span>
|
258
|
+
<small>MrLogaLoga::Configuration</small>
|
259
|
+
</div>
|
260
|
+
</li>
|
261
|
+
|
262
|
+
|
263
|
+
<li class="even ">
|
264
|
+
<div class="item">
|
265
|
+
<span class='object_link'><a href="MrLogaLoga/Logger.html#respond_to_missing%3F-instance_method" title="MrLogaLoga::Logger#respond_to_missing? (method)">#respond_to_missing?</a></span>
|
266
|
+
<small>MrLogaLoga::Logger</small>
|
267
|
+
</div>
|
268
|
+
</li>
|
269
|
+
|
270
|
+
|
271
|
+
<li class="odd ">
|
272
|
+
<div class="item">
|
273
|
+
<span class='object_link'><a href="MrLogaLoga/Context.html#respond_to_missing%3F-instance_method" title="MrLogaLoga::Context#respond_to_missing? (method)">#respond_to_missing?</a></span>
|
274
|
+
<small>MrLogaLoga::Context</small>
|
275
|
+
</div>
|
276
|
+
</li>
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
</ul>
|
281
|
+
</div>
|
282
|
+
</body>
|
283
|
+
</html>
|
@@ -0,0 +1,110 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.27
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">Top Level Namespace</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Top Level Namespace
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<h2>Defined Under Namespace</h2>
|
82
|
+
<p class="children">
|
83
|
+
|
84
|
+
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="MrLogaLoga.html" title="MrLogaLoga (module)">MrLogaLoga</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</p>
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<div id="footer">
|
103
|
+
Generated on Wed Jan 5 09:59:09 2022 by
|
104
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
|
+
0.9.27 (ruby-3.0.0).
|
106
|
+
</div>
|
107
|
+
|
108
|
+
</div>
|
109
|
+
</body>
|
110
|
+
</html>
|
data/lib/mr_loga_loga/context.rb
CHANGED
@@ -12,12 +12,22 @@ module MrLogaLoga
|
|
12
12
|
@context = context
|
13
13
|
end
|
14
14
|
|
15
|
+
# Add a new context to the log message
|
16
|
+
#
|
17
|
+
# @param context [Hash] the new context
|
18
|
+
# @yield the new context
|
19
|
+
# @return [Context] a new context object
|
15
20
|
def context(context = {}, &block)
|
16
21
|
@context = merge_context(@context, context)
|
17
22
|
@context = merge_context(@context, block)
|
18
23
|
self
|
19
24
|
end
|
20
25
|
|
26
|
+
# Log a message with the current context
|
27
|
+
#
|
28
|
+
# @param context [Hash] the new context
|
29
|
+
# @yield the new context
|
30
|
+
# @return [Context] a new context object
|
21
31
|
def add(severity, message = nil, **context, &block)
|
22
32
|
severity ||= UNKNOWN
|
23
33
|
return true unless @logger.log?(severity)
|
@@ -1,11 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'byebug'
|
4
|
-
|
5
3
|
module MrLogaLoga
|
6
|
-
module
|
7
|
-
#
|
8
|
-
|
4
|
+
module Extensions
|
5
|
+
# == Description
|
6
|
+
#
|
7
|
+
# This patches Lograge to forward data as context to MrLogaLoga.
|
8
|
+
#
|
9
|
+
# We want Lograge to forward requeest data not to it's own formatter and then to the logger, as this would make that
|
10
|
+
# data part of the message. Rather, where Lograge normally sends the formatted message to the logger we send the
|
11
|
+
# raw data.
|
12
|
+
#
|
13
|
+
# This effectively circumvents Lograge's formatters.
|
14
|
+
#
|
15
|
+
# == Patches
|
16
|
+
#
|
17
|
+
# - Lograge::LogSubscribers#process_main_event
|
18
|
+
#
|
19
|
+
module LogrageExtension
|
9
20
|
class << self
|
10
21
|
def apply
|
11
22
|
return unless defined?(Lograge)
|
@@ -13,8 +24,7 @@ module MrLogaLoga
|
|
13
24
|
patch_applies = defined?(Lograge::LogSubscribers::Base) &&
|
14
25
|
Lograge::LogSubscribers::Base.private_method_defined?(:process_main_event)
|
15
26
|
unless patch_applies
|
16
|
-
puts
|
17
|
-
"MrLogaLoga's patch no longer applies in "\
|
27
|
+
puts "WARNING: Failed to patch Lograge. It looks like MrLogaLoga's patch no longer applies in "\
|
18
28
|
"#{__FILE__}. Please contact MrLogaLoga maintainers."
|
19
29
|
return
|
20
30
|
end
|
@@ -29,6 +39,7 @@ module MrLogaLoga
|
|
29
39
|
payload = event.payload
|
30
40
|
data = extract_request(event, payload)
|
31
41
|
data = before_format(data, payload)
|
42
|
+
# Instead of
|
32
43
|
if logger.is_a?(MrLogaLoga::Logger)
|
33
44
|
logger.send(Lograge.log_level, '', **data)
|
34
45
|
else
|
@@ -40,4 +51,4 @@ module MrLogaLoga
|
|
40
51
|
end
|
41
52
|
end
|
42
53
|
|
43
|
-
MrLogaLoga::
|
54
|
+
MrLogaLoga::Extensions::LogrageExtension.apply
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MrLogaLoga
|
4
|
+
module Extensions
|
5
|
+
# == Description
|
6
|
+
#
|
7
|
+
# This patches Rails to allow it to work with loggers that accept keyword arguments.
|
8
|
+
#
|
9
|
+
# Per default, Rails patches any logger during server startup to be able to broadcast any log messages to the
|
10
|
+
# console. This patch assumes that loggers only take args and blocks, so we have to change that.
|
11
|
+
#
|
12
|
+
# During server startup Rails will always use the ActiveSupport::Logger to send data to the console.
|
13
|
+
# This was modified o changed to always use the user-configured logger.
|
14
|
+
#
|
15
|
+
# == Patches
|
16
|
+
#
|
17
|
+
# - {ActiveSupport::Logger#self.broadcast}
|
18
|
+
# - {Rails::Server#log_to_stdout}
|
19
|
+
#
|
20
|
+
module RailsExtension
|
21
|
+
class << self
|
22
|
+
def apply
|
23
|
+
return unless defined?(Rails)
|
24
|
+
|
25
|
+
logger_defined = defined?(ActiveSupport::Logger)
|
26
|
+
unless logger_defined && broadcast_method
|
27
|
+
puts "WARNING: Failed to patch ActiveSupport::Logger. It looks like MrLogaLoga's patch in #{__FILE__} no "\
|
28
|
+
"longer applies. Please contact MrLogaLoga's maintainers."
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
server_defined = defined?(Rails::Server)
|
33
|
+
unless server_defined && Rails::Server.private_method_defined?(:log_to_stdout)
|
34
|
+
puts "WARNING: Failed to patch Rails::Server. It looks like MrLogaLoga's patch in #{__FILE__} no "\
|
35
|
+
"longer applies. Please contact MrLogaLoga's maintainers."
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
ActiveSupport::Logger.include(LoggerPatch)
|
40
|
+
Rails::Server.prepend(ServerPatch)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def broadcast_method
|
46
|
+
broadcast = ActiveSupport::Logger.method(:broadcast)
|
47
|
+
broadcast && broadcast.arity == 1
|
48
|
+
rescue NameError
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
# This patches ActiveSupport::Logger to allow properly formatting keyword arguments
|
53
|
+
module LoggerPatch
|
54
|
+
# rubocop:disable all
|
55
|
+
def included base
|
56
|
+
base.instance_eval do
|
57
|
+
def broadcast(logger)
|
58
|
+
Module.new do
|
59
|
+
# We need to patch this method as otherwise calling add with keyword arguments results in argument errors.
|
60
|
+
# Rails calls `broadcast` for the logger configured in `Rails.logger`, which means that any invocations of
|
61
|
+
# Rails.logger.add result in running through this method.
|
62
|
+
#
|
63
|
+
# TODO: Remove once patched in Rails
|
64
|
+
define_method(:add) do |*args, **kwargs, &block|
|
65
|
+
logger.add(*args, **kwargs, &block)
|
66
|
+
super(*args, **kwargs, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
define_method(:<<) do |x|
|
70
|
+
logger << x
|
71
|
+
super(x)
|
72
|
+
end
|
73
|
+
|
74
|
+
define_method(:close) do
|
75
|
+
logger.close
|
76
|
+
super()
|
77
|
+
end
|
78
|
+
|
79
|
+
define_method(:progname=) do |name|
|
80
|
+
logger.progname = name
|
81
|
+
super(name)
|
82
|
+
end
|
83
|
+
|
84
|
+
define_method(:formatter=) do |formatter|
|
85
|
+
logger.formatter = formatter
|
86
|
+
super(formatter)
|
87
|
+
end
|
88
|
+
|
89
|
+
define_method(:level=) do |level|
|
90
|
+
logger.level = level
|
91
|
+
super(level)
|
92
|
+
end
|
93
|
+
|
94
|
+
define_method(:local_level=) do |level|
|
95
|
+
logger.local_level = level if logger.respond_to?(:local_level=)
|
96
|
+
super(level) if respond_to?(:local_level=)
|
97
|
+
end
|
98
|
+
|
99
|
+
define_method(:silence) do |level = Logger::ERROR, &block|
|
100
|
+
if logger.respond_to?(:silence)
|
101
|
+
logger.silence(level) do
|
102
|
+
if defined?(super)
|
103
|
+
super(level, &block)
|
104
|
+
else
|
105
|
+
block.call(self)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
else
|
109
|
+
if defined?(super)
|
110
|
+
super(level, &block)
|
111
|
+
else
|
112
|
+
block.call(self)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
# rubocpo:enable all
|
121
|
+
end
|
122
|
+
|
123
|
+
# This patches the server command so that console output will use the same logger you previously configured
|
124
|
+
module ServerPatch
|
125
|
+
def log_to_stdout
|
126
|
+
wrapped_app # touch the app so the logger is set up
|
127
|
+
|
128
|
+
console = Rails.logger.class.new(STDOUT)
|
129
|
+
console.formatter = Rails.logger.formatter
|
130
|
+
console.level = Rails.logger.level
|
131
|
+
|
132
|
+
unless ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT)
|
133
|
+
Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
MrLogaLoga::Extensions::RailsExtension.apply
|
@@ -20,19 +20,19 @@ module MrLogaLoga
|
|
20
20
|
# @param severity [String] The message severity
|
21
21
|
# @param datetime [DateTime] The message date time
|
22
22
|
# @param progname [DateTime] The program name
|
23
|
-
# @param message [
|
23
|
+
# @param message [Object] The log message, which may not be a string
|
24
24
|
# @param context [Hash] The log message context
|
25
25
|
#
|
26
26
|
# @return [String] the formatted log message
|
27
|
-
def call(severity, datetime, progname, message, context)
|
28
|
-
message = message.nil?
|
27
|
+
def call(severity, datetime, progname, message, **context)
|
28
|
+
message = message.nil? ? '' : msg2str(message).strip
|
29
29
|
|
30
30
|
message_hash = {
|
31
31
|
severity: severity,
|
32
32
|
datetime: datetime.strftime('%Y-%m-%dT%H:%M:%S.%6N'),
|
33
33
|
pid: Process.pid,
|
34
34
|
progname: progname,
|
35
|
-
message: message,
|
35
|
+
message: (message.empty? ? nil : message),
|
36
36
|
**context
|
37
37
|
}.compact
|
38
38
|
"#{message_hash.to_json}\n"
|
@@ -24,7 +24,8 @@ module MrLogaLoga
|
|
24
24
|
# @param context [Hash] The log message context
|
25
25
|
#
|
26
26
|
# @return [String] the formatted log message
|
27
|
-
def call(severity, datetime, progname, message, context)
|
27
|
+
def call(severity, datetime, progname, message, **context)
|
28
|
+
message = msg2str(message).strip
|
28
29
|
message = context.map { |key, value| "#{key}=#{value}" }
|
29
30
|
.prepend(message)
|
30
31
|
.compact
|
@@ -11,13 +11,19 @@ module MrLogaLoga
|
|
11
11
|
{ class_name: self.class.name }
|
12
12
|
end
|
13
13
|
|
14
|
+
# A shorthand method to use in your classes
|
14
15
|
def logger
|
15
|
-
MrLogaLoga::
|
16
|
+
if loga_loga.is_a?(MrLogaLoga::Logger)
|
17
|
+
MrLogaLoga::LoggerProxy.new(loga_loga, -> { loga_context })
|
18
|
+
else
|
19
|
+
loga_loga
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
23
|
+
# Define the underlying logger to be used. Overwrite this to use a specific logger instance
|
18
24
|
def loga_loga
|
19
|
-
@loga_loga ||= if defined?(Rails.
|
20
|
-
Rails.
|
25
|
+
@loga_loga ||= if defined?(Rails.logger)
|
26
|
+
Rails.logger
|
21
27
|
else
|
22
28
|
MrLogaLoga.configuration.logger
|
23
29
|
end
|