mr_loga_loga 0.1.1 → 0.1.2
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/.github/workflows/release.yml +2 -2
- data/.gitignore +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +7 -3
- data/README.md +4 -4
- 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 -6
- data/lib/mr_loga_loga/extensions/rails.rb +142 -0
- data/lib/mr_loga_loga/instance_methods.rb +5 -1
- data/lib/mr_loga_loga/logger.rb +3 -5
- data/lib/mr_loga_loga/version.rb +1 -1
- data/lib/mr_loga_loga.rb +3 -3
- data/mr_loga_loga.gemspec +3 -2
- metadata +53 -8
- data/lib/mr_loga_loga/extensions/active_support_logger_patch.rb +0 -94
@@ -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,9 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module MrLogaLoga
|
4
|
-
module
|
5
|
-
#
|
6
|
-
|
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
|
7
20
|
class << self
|
8
21
|
def apply
|
9
22
|
return unless defined?(Lograge)
|
@@ -11,8 +24,7 @@ module MrLogaLoga
|
|
11
24
|
patch_applies = defined?(Lograge::LogSubscribers::Base) &&
|
12
25
|
Lograge::LogSubscribers::Base.private_method_defined?(:process_main_event)
|
13
26
|
unless patch_applies
|
14
|
-
puts
|
15
|
-
"MrLogaLoga's patch no longer applies in "\
|
27
|
+
puts "WARNING: Failed to patch Lograge. It looks like MrLogaLoga's patch no longer applies in "\
|
16
28
|
"#{__FILE__}. Please contact MrLogaLoga maintainers."
|
17
29
|
return
|
18
30
|
end
|
@@ -27,6 +39,7 @@ module MrLogaLoga
|
|
27
39
|
payload = event.payload
|
28
40
|
data = extract_request(event, payload)
|
29
41
|
data = before_format(data, payload)
|
42
|
+
# Instead of
|
30
43
|
if logger.is_a?(MrLogaLoga::Logger)
|
31
44
|
logger.send(Lograge.log_level, '', **data)
|
32
45
|
else
|
@@ -38,4 +51,4 @@ module MrLogaLoga
|
|
38
51
|
end
|
39
52
|
end
|
40
53
|
|
41
|
-
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
|
@@ -12,7 +12,11 @@ module MrLogaLoga
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def logger
|
15
|
-
MrLogaLoga::
|
15
|
+
if loga_loga.is_a?(MrLogaLoga::Logger)
|
16
|
+
MrLogaLoga::LoggerProxy.new(loga_loga, -> { loga_context })
|
17
|
+
else
|
18
|
+
loga_loga
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def loga_loga
|
data/lib/mr_loga_loga/logger.rb
CHANGED
@@ -19,22 +19,20 @@ module MrLogaLoga
|
|
19
19
|
#
|
20
20
|
# logger.debug("Default")
|
21
21
|
# logger.context(user: 1).debug('with context')
|
22
|
+
#
|
22
23
|
class Logger < ::Logger
|
23
24
|
def initialize(*args, **kwargs)
|
24
25
|
super
|
25
26
|
@default_formatter = MrLogaLoga::Formatters::KeyValue.new
|
26
27
|
end
|
27
28
|
|
29
|
+
# Generates a new context
|
28
30
|
def context(**kwargs, &block)
|
29
31
|
context = block ? -> { kwargs.merge(block.call) } : kwargs
|
30
32
|
Context.new(self, context)
|
31
33
|
end
|
32
34
|
|
33
|
-
|
34
|
-
message ||= block
|
35
|
-
Message.new(self, message)
|
36
|
-
end
|
37
|
-
|
35
|
+
# Adds a new log message with the given severity
|
38
36
|
def add(severity, message = nil, progname = nil, *_args, **context, &block)
|
39
37
|
severity ||= UNKNOWN
|
40
38
|
return true unless log?(severity)
|
data/lib/mr_loga_loga/version.rb
CHANGED
data/lib/mr_loga_loga.rb
CHANGED
@@ -9,10 +9,10 @@ require_relative 'mr_loga_loga/logger'
|
|
9
9
|
require_relative 'mr_loga_loga/formatters/key_value'
|
10
10
|
require_relative 'mr_loga_loga/formatters/json'
|
11
11
|
|
12
|
-
require_relative 'mr_loga_loga/extensions/
|
13
|
-
require_relative 'mr_loga_loga/extensions/
|
12
|
+
require_relative 'mr_loga_loga/extensions/rails'
|
13
|
+
require_relative 'mr_loga_loga/extensions/lograge'
|
14
14
|
|
15
|
-
#
|
15
|
+
# ## Description
|
16
16
|
#
|
17
17
|
# The MrLogaLoga module provides additional logging functionality when included in your classes.
|
18
18
|
#
|
data/mr_loga_loga.gemspec
CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
# For more information and examples about making a new gem, checkout our
|
35
35
|
# guide at: https://bundler.io/guides/creating_gem.html
|
36
36
|
spec.add_development_dependency 'rubocop', '~> 1.24'
|
37
|
-
spec.add_development_dependency 'simplecov', '~> 0.21
|
38
|
-
spec.add_development_dependency 'timecop', '~> 0.9
|
37
|
+
spec.add_development_dependency 'simplecov', '~> 0.21'
|
38
|
+
spec.add_development_dependency 'timecop', '~> 0.9'
|
39
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
39
40
|
end
|