cogger 0.0.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
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.adoc +134 -0
- data/README.adoc +249 -0
- data/cogger.gemspec +30 -0
- data/lib/cogger/client.rb +47 -0
- data/lib/cogger/color.rb +40 -0
- data/lib/cogger/refinements/log_devices.rb +21 -0
- data/lib/cogger/refinements/loggers.rb +16 -0
- data/lib/cogger.rb +9 -0
- data.tar.gz.sig +0 -0
- metadata +107 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 465a15ec3c5e20f27ef9956b05cc8f2899ef686317e226ba5b16830c3db153de
|
|
4
|
+
data.tar.gz: '06861836951ec57ffb8dcfe10dcdcb8914eea7264725a53b34302a09e21a8e08'
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f0e509f2aa695e350fca06ac740de063bfa31e5971923b96697ee6d0ef47b2ea512cc2f1988b32833efc99303c5f9eca89d3135f7499dc7fda8f2f8e49cbcbe0
|
|
7
|
+
data.tar.gz: aef3da2c06270335364bc4d164743aa85c86730eb317677c8efdb4264922098b810104f21b744aa728992fe9c9e919dea085909dee7edf564c28083613652d32
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
data/LICENSE.adoc
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
= Hippocratic License
|
|
2
|
+
|
|
3
|
+
Version: 2.1.0.
|
|
4
|
+
|
|
5
|
+
Purpose. The purpose of this License is for the Licensor named above to
|
|
6
|
+
permit the Licensee (as defined below) broad permission, if consistent
|
|
7
|
+
with Human Rights Laws and Human Rights Principles (as each is defined
|
|
8
|
+
below), to use and work with the Software (as defined below) within the
|
|
9
|
+
full scope of Licensor’s copyright and patent rights, if any, in the
|
|
10
|
+
Software, while ensuring attribution and protecting the Licensor from
|
|
11
|
+
liability.
|
|
12
|
+
|
|
13
|
+
Permission and Conditions. The Licensor grants permission by this
|
|
14
|
+
license ("License"), free of charge, to the extent of Licensor’s
|
|
15
|
+
rights under applicable copyright and patent law, to any person or
|
|
16
|
+
entity (the "Licensee") obtaining a copy of this software and
|
|
17
|
+
associated documentation files (the "Software"), to do everything with
|
|
18
|
+
the Software that would otherwise infringe (i) the Licensor’s copyright
|
|
19
|
+
in the Software or (ii) any patent claims to the Software that the
|
|
20
|
+
Licensor can license or becomes able to license, subject to all of the
|
|
21
|
+
following terms and conditions:
|
|
22
|
+
|
|
23
|
+
* Acceptance. This License is automatically offered to every person and
|
|
24
|
+
entity subject to its terms and conditions. Licensee accepts this
|
|
25
|
+
License and agrees to its terms and conditions by taking any action with
|
|
26
|
+
the Software that, absent this License, would infringe any intellectual
|
|
27
|
+
property right held by Licensor.
|
|
28
|
+
* Notice. Licensee must ensure that everyone who gets a copy of any part
|
|
29
|
+
of this Software from Licensee, with or without changes, also receives
|
|
30
|
+
the License and the above copyright notice (and if included by the
|
|
31
|
+
Licensor, patent, trademark and attribution notice). Licensee must cause
|
|
32
|
+
any modified versions of the Software to carry prominent notices stating
|
|
33
|
+
that Licensee changed the Software. For clarity, although Licensee is
|
|
34
|
+
free to create modifications of the Software and distribute only the
|
|
35
|
+
modified portion created by Licensee with additional or different terms,
|
|
36
|
+
the portion of the Software not modified must be distributed pursuant to
|
|
37
|
+
this License. If anyone notifies Licensee in writing that Licensee has
|
|
38
|
+
not complied with this Notice section, Licensee can keep this License by
|
|
39
|
+
taking all practical steps to comply within 30 days after the notice. If
|
|
40
|
+
Licensee does not do so, Licensee’s License (and all rights licensed
|
|
41
|
+
hereunder) shall end immediately.
|
|
42
|
+
* Compliance with Human Rights Principles and Human Rights Laws.
|
|
43
|
+
[arabic]
|
|
44
|
+
. Human Rights Principles.
|
|
45
|
+
[loweralpha]
|
|
46
|
+
.. Licensee is advised to consult the articles of the United Nations
|
|
47
|
+
Universal Declaration of Human Rights and the United Nations Global
|
|
48
|
+
Compact that define recognized principles of international human rights
|
|
49
|
+
(the "Human Rights Principles"). Licensee shall use the Software in a
|
|
50
|
+
manner consistent with Human Rights Principles.
|
|
51
|
+
.. Unless the Licensor and Licensee agree otherwise, any dispute,
|
|
52
|
+
controversy, or claim arising out of or relating to (i) Section 1(a)
|
|
53
|
+
regarding Human Rights Principles, including the breach of Section 1(a),
|
|
54
|
+
termination of this License for breach of the Human Rights Principles,
|
|
55
|
+
or invalidity of Section 1(a) or (ii) a determination of whether any Law
|
|
56
|
+
is consistent or in conflict with Human Rights Principles pursuant to
|
|
57
|
+
Section 2, below, shall be settled by arbitration in accordance with the
|
|
58
|
+
Hague Rules on Business and Human Rights Arbitration (the "Rules");
|
|
59
|
+
provided, however, that Licensee may elect not to participate in such
|
|
60
|
+
arbitration, in which event this License (and all rights licensed
|
|
61
|
+
hereunder) shall end immediately. The number of arbitrators shall be one
|
|
62
|
+
unless the Rules require otherwise.
|
|
63
|
+
+
|
|
64
|
+
Unless both the Licensor and Licensee agree to the contrary: (1) All
|
|
65
|
+
documents and information concerning the arbitration shall be public and
|
|
66
|
+
may be disclosed by any party; (2) The repository referred to under
|
|
67
|
+
Article 43 of the Rules shall make available to the public in a timely
|
|
68
|
+
manner all documents concerning the arbitration which are communicated
|
|
69
|
+
to it, including all submissions of the parties, all evidence admitted
|
|
70
|
+
into the record of the proceedings, all transcripts or other recordings
|
|
71
|
+
of hearings and all orders, decisions and awards of the arbitral
|
|
72
|
+
tribunal, subject only to the arbitral tribunal’s powers to take such
|
|
73
|
+
measures as may be necessary to safeguard the integrity of the arbitral
|
|
74
|
+
process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3)
|
|
75
|
+
Article 26(6) of the Rules shall not apply.
|
|
76
|
+
. Human Rights Laws. The Software shall not be used by any person or
|
|
77
|
+
entity for any systems, activities, or other uses that violate any Human
|
|
78
|
+
Rights Laws. "Human Rights Laws" means any applicable laws,
|
|
79
|
+
regulations, or rules (collectively, "Laws") that protect human,
|
|
80
|
+
civil, labor, privacy, political, environmental, security, economic, due
|
|
81
|
+
process, or similar rights; provided, however, that such Laws are
|
|
82
|
+
consistent and not in conflict with Human Rights Principles (a dispute
|
|
83
|
+
over the consistency or a conflict between Laws and Human Rights
|
|
84
|
+
Principles shall be determined by arbitration as stated above). Where
|
|
85
|
+
the Human Rights Laws of more than one jurisdiction are applicable or in
|
|
86
|
+
conflict with respect to the use of the Software, the Human Rights Laws
|
|
87
|
+
that are most protective of the individuals or groups harmed shall
|
|
88
|
+
apply.
|
|
89
|
+
. Indemnity. Licensee shall hold harmless and indemnify Licensor (and
|
|
90
|
+
any other contributor) against all losses, damages, liabilities,
|
|
91
|
+
deficiencies, claims, actions, judgments, settlements, interest, awards,
|
|
92
|
+
penalties, fines, costs, or expenses of whatever kind, including
|
|
93
|
+
Licensor’s reasonable attorneys’ fees, arising out of or relating to
|
|
94
|
+
Licensee’s use of the Software in violation of Human Rights Laws or
|
|
95
|
+
Human Rights Principles.
|
|
96
|
+
* Failure to Comply. Any failure of Licensee to act according to the
|
|
97
|
+
terms and conditions of this License is both a breach of the License and
|
|
98
|
+
an infringement of the intellectual property rights of the Licensor
|
|
99
|
+
(subject to exceptions under Laws, e.g., fair use). In the event of a
|
|
100
|
+
breach or infringement, the terms and conditions of this License may be
|
|
101
|
+
enforced by Licensor under the Laws of any jurisdiction to which
|
|
102
|
+
Licensee is subject. Licensee also agrees that the Licensor may enforce
|
|
103
|
+
the terms and conditions of this License against Licensee through
|
|
104
|
+
specific performance (or similar remedy under Laws) to the extent
|
|
105
|
+
permitted by Laws. For clarity, except in the event of a breach of this
|
|
106
|
+
License, infringement, or as otherwise stated in this License, Licensor
|
|
107
|
+
may not terminate this License with Licensee.
|
|
108
|
+
* Enforceability and Interpretation. If any term or provision of this
|
|
109
|
+
License is determined to be invalid, illegal, or unenforceable by a
|
|
110
|
+
court of competent jurisdiction, then such invalidity, illegality, or
|
|
111
|
+
unenforceability shall not affect any other term or provision of this
|
|
112
|
+
License or invalidate or render unenforceable such term or provision in
|
|
113
|
+
any other jurisdiction; provided, however, subject to a court
|
|
114
|
+
modification pursuant to the immediately following sentence, if any term
|
|
115
|
+
or provision of this License pertaining to Human Rights Laws or Human
|
|
116
|
+
Rights Principles is deemed invalid, illegal, or unenforceable against
|
|
117
|
+
Licensee by a court of competent jurisdiction, all rights in the
|
|
118
|
+
Software granted to Licensee shall be deemed null and void as between
|
|
119
|
+
Licensor and Licensee. Upon a determination that any term or provision
|
|
120
|
+
is invalid, illegal, or unenforceable, to the extent permitted by Laws,
|
|
121
|
+
the court may modify this License to affect the original purpose that
|
|
122
|
+
the Software be used in compliance with Human Rights Principles and
|
|
123
|
+
Human Rights Laws as closely as possible. The language in this License
|
|
124
|
+
shall be interpreted as to its fair meaning and not strictly for or
|
|
125
|
+
against any party.
|
|
126
|
+
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES
|
|
127
|
+
"AS IS," WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND
|
|
128
|
+
ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR
|
|
129
|
+
OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
|
130
|
+
OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
|
131
|
+
|
|
132
|
+
This Hippocratic License is an link:https://ethicalsource.dev[Ethical Source license] and is offered
|
|
133
|
+
for use by licensors and licensees at their own risk, on an "AS IS" basis, and with no warranties
|
|
134
|
+
express or implied, to the maximum extent permitted by Laws.
|
data/README.adoc
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
:pastel_link: link:https://github.com/piotrmurach/pastel[Pastel]
|
|
2
|
+
|
|
3
|
+
:toc: macro
|
|
4
|
+
:toclevels: 5
|
|
5
|
+
:figure-caption!:
|
|
6
|
+
|
|
7
|
+
= Cogger
|
|
8
|
+
|
|
9
|
+
Cogger is a portmanteau for colorized logging (i.e. `[c]olorized + l[ogger] = cogger`) which
|
|
10
|
+
decorates Ruby's native logger with colorized output.
|
|
11
|
+
|
|
12
|
+
toc::[]
|
|
13
|
+
|
|
14
|
+
== Features
|
|
15
|
+
|
|
16
|
+
- Decorates Ruby's default `Logger`.
|
|
17
|
+
- Uses color decoration as provided by the {pastel_link} gem.
|
|
18
|
+
|
|
19
|
+
== Screenshot
|
|
20
|
+
|
|
21
|
+
image::https://www.alchemists.io/images/projects/cogger/screenshots/console.png[Console,width=552,height=679,role=focal_point]
|
|
22
|
+
|
|
23
|
+
== Requirements
|
|
24
|
+
|
|
25
|
+
. link:https://www.ruby-lang.org[Ruby].
|
|
26
|
+
|
|
27
|
+
== Setup
|
|
28
|
+
|
|
29
|
+
To set up the project, run:
|
|
30
|
+
|
|
31
|
+
[source,bash]
|
|
32
|
+
----
|
|
33
|
+
bin/setup
|
|
34
|
+
----
|
|
35
|
+
|
|
36
|
+
== Usage
|
|
37
|
+
|
|
38
|
+
All colorized logging is provided by the `Cogger::Client` class which can be used as follows:
|
|
39
|
+
|
|
40
|
+
[source,ruby]
|
|
41
|
+
----
|
|
42
|
+
logger = Cogger::Client.new
|
|
43
|
+
|
|
44
|
+
logger.debug "test" # true
|
|
45
|
+
logger.debug { "test" } # true
|
|
46
|
+
logger.info "test" # true
|
|
47
|
+
logger.info { "test" } # true
|
|
48
|
+
logger.warn "test" # true
|
|
49
|
+
logger.warn { "test" } # true
|
|
50
|
+
logger.error "test" # true
|
|
51
|
+
logger.error { "test" } # true
|
|
52
|
+
logger.fatal "test" # true
|
|
53
|
+
logger.fatal { "test" } # true
|
|
54
|
+
logger.any "test" # true
|
|
55
|
+
logger.any { "test" } # true
|
|
56
|
+
----
|
|
57
|
+
|
|
58
|
+
By default, all logging is configured to use `INFO` level and writes to `$stdout`. To see what the
|
|
59
|
+
colorized output from the above looks like, please see the screenshot shown in the _Screenshots_
|
|
60
|
+
section as documented earlier.
|
|
61
|
+
|
|
62
|
+
Beyond the standard log level methods, the following methods are also available:
|
|
63
|
+
|
|
64
|
+
[source,ruby]
|
|
65
|
+
----
|
|
66
|
+
logger = Cogger::Client.new
|
|
67
|
+
|
|
68
|
+
logger.formatter # #<Proc:0x000000010626ebc8 $HOME/OSS/cogger/lib/cogger/client.rb:37 (lambda)>
|
|
69
|
+
logger.level # 1
|
|
70
|
+
logger.progname # nil
|
|
71
|
+
----
|
|
72
|
+
|
|
73
|
+
=== Customization
|
|
74
|
+
|
|
75
|
+
Customization of the logger differs, slightly, from what you'd get with the standard `Logger` class.
|
|
76
|
+
The following sections will explain what these differences look like.
|
|
77
|
+
|
|
78
|
+
==== Initialization
|
|
79
|
+
|
|
80
|
+
For starters, the first argument is a positional argument that defaults to `Logger.new($stdout)` but
|
|
81
|
+
you could swap out the default logger with something that logs to a string. For example:
|
|
82
|
+
|
|
83
|
+
[source,ruby]
|
|
84
|
+
----
|
|
85
|
+
logger = Cogger::Client.new Logger.new(StringIO.new)
|
|
86
|
+
----
|
|
87
|
+
|
|
88
|
+
You can also create a logger which might use custom colors. Example:
|
|
89
|
+
|
|
90
|
+
[source,ruby]
|
|
91
|
+
----
|
|
92
|
+
logger = Cogger::Client.new color: MyColor.new
|
|
93
|
+
----
|
|
94
|
+
|
|
95
|
+
More information on how to customize your colors will be provided later.
|
|
96
|
+
|
|
97
|
+
Lastly, you can provide any _setable_ attribute which would normally be used when constructing a
|
|
98
|
+
normal logger. Example:
|
|
99
|
+
|
|
100
|
+
[source,ruby]
|
|
101
|
+
----
|
|
102
|
+
logger = Cogger::Client.new formatter: ->(severity, _at, _name, message) { "#{message}\n" },
|
|
103
|
+
level: :debug,
|
|
104
|
+
progname: "Test",
|
|
105
|
+
datetime_format: "%Y-%m-%d"
|
|
106
|
+
----
|
|
107
|
+
|
|
108
|
+
Alternatively, you can use a block as well:
|
|
109
|
+
|
|
110
|
+
[source,ruby]
|
|
111
|
+
----
|
|
112
|
+
logger = Cogger::Client.new do |instance|
|
|
113
|
+
instance.formatter = ->(severity, _at, _name, message) { "#{message}\n" }
|
|
114
|
+
instance.level = :debug
|
|
115
|
+
instance.progname = "Test"
|
|
116
|
+
instance.datetime_format = "%Y-%m-%d"
|
|
117
|
+
end
|
|
118
|
+
----
|
|
119
|
+
|
|
120
|
+
==== Levels
|
|
121
|
+
|
|
122
|
+
The default log level is `INFO` but can be customized via your environment. For instance, you could
|
|
123
|
+
set the logging level to any of the following:
|
|
124
|
+
|
|
125
|
+
[source,bash]
|
|
126
|
+
----
|
|
127
|
+
export LOG_LEVEL=DEBUG
|
|
128
|
+
export LOG_LEVEL=INFO
|
|
129
|
+
export LOG_LEVEL=WARN
|
|
130
|
+
export LOG_LEVEL=ERROR
|
|
131
|
+
export LOG_LEVEL=FATAL
|
|
132
|
+
export LOG_LEVEL=ANY
|
|
133
|
+
----
|
|
134
|
+
|
|
135
|
+
By default, `Cogger::Client` will automatically use whatever is set via the `LOG_LEVEL` environment
|
|
136
|
+
variable unless overwritten during initialization.
|
|
137
|
+
|
|
138
|
+
==== Colorization
|
|
139
|
+
|
|
140
|
+
Default colors are provided by the `Cogger::Color` class which are keyed by log level:
|
|
141
|
+
|
|
142
|
+
[source,ruby]
|
|
143
|
+
----
|
|
144
|
+
{
|
|
145
|
+
debug: %i[white],
|
|
146
|
+
info: %i[green],
|
|
147
|
+
warn: %i[yellow],
|
|
148
|
+
error: %i[red],
|
|
149
|
+
fatal: %i[white bold on_red],
|
|
150
|
+
any: %i[white bold]
|
|
151
|
+
}
|
|
152
|
+
----
|
|
153
|
+
|
|
154
|
+
All keys require an array of styles which can then be decorated by {pastel_link}. This means that if
|
|
155
|
+
you wanted to use custom colors, you could create a new instance of the `Color` class and inject it
|
|
156
|
+
into the client as follows:
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
[source,ruby]
|
|
160
|
+
----
|
|
161
|
+
custom_color = Cogger::Color.new(
|
|
162
|
+
defaults: {
|
|
163
|
+
debug: %i[white on_black],
|
|
164
|
+
info: %i[green on_black],
|
|
165
|
+
warn: %i[yellow on_black],
|
|
166
|
+
error: %i[red on_black],
|
|
167
|
+
fatal: %i[red on_black],
|
|
168
|
+
any: %i[white on_black]
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
logger = Cogger::Client.new color: custom_color
|
|
173
|
+
----
|
|
174
|
+
|
|
175
|
+
The above would ensure all log level colors are displayed on a black background. Basically, any
|
|
176
|
+
style accepted by `Pastel#decorate` method is supported.
|
|
177
|
+
|
|
178
|
+
==== Testing
|
|
179
|
+
|
|
180
|
+
When testing the Cogger client, you might find it convenient to use `StringIO`, or a file, for
|
|
181
|
+
logging purposes in order to not pollute your test output but also have a convenient way to see what
|
|
182
|
+
was logged. Example:
|
|
183
|
+
|
|
184
|
+
[source,ruby]
|
|
185
|
+
----
|
|
186
|
+
class Demo
|
|
187
|
+
def initialize logger: Cogger::Logger.new
|
|
188
|
+
@logger = logger
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def say(text) = logger.info { text }
|
|
192
|
+
|
|
193
|
+
private
|
|
194
|
+
|
|
195
|
+
attr_reader :logger
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
RSpec.describe Demo do
|
|
199
|
+
subject(:demo) { described_class.new logger: }
|
|
200
|
+
|
|
201
|
+
let(:logger) { Cogger::Logger.new Logger.new(StringIO.new) }
|
|
202
|
+
|
|
203
|
+
describe "#say" do
|
|
204
|
+
it "logs text" do
|
|
205
|
+
demo.say "Hi"
|
|
206
|
+
expect(logger.reread).to include("Hi")
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
----
|
|
211
|
+
|
|
212
|
+
Notice that when testing the instance of `Demo` and injecting a logger which logs to a string I/O
|
|
213
|
+
object, you can conveniently reread that string to see what was logged. This makes your specs easier
|
|
214
|
+
to write while also not adding additional noise to your test suite's output.
|
|
215
|
+
|
|
216
|
+
== Development
|
|
217
|
+
|
|
218
|
+
You can also use the IRB console for direct access to all objects:
|
|
219
|
+
|
|
220
|
+
[source,bash]
|
|
221
|
+
----
|
|
222
|
+
bin/console
|
|
223
|
+
----
|
|
224
|
+
|
|
225
|
+
== Tests
|
|
226
|
+
|
|
227
|
+
To test, run:
|
|
228
|
+
|
|
229
|
+
[source,bash]
|
|
230
|
+
----
|
|
231
|
+
bundle exec rake
|
|
232
|
+
----
|
|
233
|
+
|
|
234
|
+
== link:https://www.alchemists.io/policies/license[License]
|
|
235
|
+
|
|
236
|
+
== link:https://www.alchemists.io/policies/security[Security]
|
|
237
|
+
|
|
238
|
+
== link:https://www.alchemists.io/policies/code_of_conduct[Code of Conduct]
|
|
239
|
+
|
|
240
|
+
== link:https://www.alchemists.io/policies/contributions[Contributions]
|
|
241
|
+
|
|
242
|
+
== link:https://www.alchemists.io/projects/cogger/versions[Versions]
|
|
243
|
+
|
|
244
|
+
== link:https://www.alchemists.io/community[Community]
|
|
245
|
+
|
|
246
|
+
== Credits
|
|
247
|
+
|
|
248
|
+
* Built with link:https://www.alchemists.io/projects/gemsmith[Gemsmith].
|
|
249
|
+
* Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].
|
data/cogger.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "cogger"
|
|
5
|
+
spec.version = "0.0.0"
|
|
6
|
+
spec.authors = ["Brooke Kuhlmann"]
|
|
7
|
+
spec.email = ["brooke@alchemists.io"]
|
|
8
|
+
spec.homepage = "https://www.alchemists.io/projects/cogger"
|
|
9
|
+
spec.summary = "Decorates native logging with colorized output."
|
|
10
|
+
spec.license = "Hippocratic-2.1"
|
|
11
|
+
|
|
12
|
+
spec.metadata = {
|
|
13
|
+
"bug_tracker_uri" => "https://github.com/bkuhlmann/cogger/issues",
|
|
14
|
+
"changelog_uri" => "https://www.alchemists.io/projects/cogger/versions",
|
|
15
|
+
"documentation_uri" => "https://www.alchemists.io/projects/cogger",
|
|
16
|
+
"label" => "Cogger",
|
|
17
|
+
"rubygems_mfa_required" => "true",
|
|
18
|
+
"source_code_uri" => "https://github.com/bkuhlmann/cogger"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
spec.signing_key = Gem.default_key_path
|
|
22
|
+
spec.cert_chain = [Gem.default_cert_path]
|
|
23
|
+
|
|
24
|
+
spec.required_ruby_version = "~> 3.1"
|
|
25
|
+
spec.add_dependency "pastel", "~> 0.8"
|
|
26
|
+
spec.add_dependency "zeitwerk", "~> 2.5"
|
|
27
|
+
|
|
28
|
+
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
|
29
|
+
spec.files = Dir["*.gemspec", "lib/**/*"]
|
|
30
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "forwardable"
|
|
4
|
+
require "logger"
|
|
5
|
+
|
|
6
|
+
module Cogger
|
|
7
|
+
# Provides the primary client for colorized logging.
|
|
8
|
+
class Client
|
|
9
|
+
extend Forwardable
|
|
10
|
+
|
|
11
|
+
using Refinements::Loggers
|
|
12
|
+
|
|
13
|
+
delegate %i[formatter level progname debug info warn error fatal] => :logger
|
|
14
|
+
|
|
15
|
+
def initialize logger = Logger.new($stdout), color: Color.new, **attributes
|
|
16
|
+
@logger = logger
|
|
17
|
+
@color = color
|
|
18
|
+
@attributes = attributes
|
|
19
|
+
|
|
20
|
+
configure
|
|
21
|
+
yield logger if block_given?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def any(...) = logger.unknown(...)
|
|
25
|
+
|
|
26
|
+
def reread = logger.reread
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
attr_reader :logger, :color, :attributes
|
|
31
|
+
|
|
32
|
+
# rubocop:disable Metrics/AbcSize
|
|
33
|
+
def configure
|
|
34
|
+
logger.datetime_format = attributes.fetch :datetime_format, logger.datetime_format
|
|
35
|
+
logger.level = attributes.fetch :level, default_level
|
|
36
|
+
logger.progname = attributes.fetch :progname, logger.progname
|
|
37
|
+
logger.formatter = attributes.fetch :formatter, default_formatter
|
|
38
|
+
end
|
|
39
|
+
# rubocop:enable Metrics/AbcSize
|
|
40
|
+
|
|
41
|
+
def default_level = logger.class.const_get ENV.fetch("LOG_LEVEL", "INFO")
|
|
42
|
+
|
|
43
|
+
def default_formatter
|
|
44
|
+
->(severity, _at, _name, message) { "#{color.public_send severity.downcase, message}\n" }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/cogger/color.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pastel"
|
|
4
|
+
|
|
5
|
+
module Cogger
|
|
6
|
+
# Provides default colors for all log levels.
|
|
7
|
+
class Color
|
|
8
|
+
DEFAULTS = {
|
|
9
|
+
debug: %i[white],
|
|
10
|
+
info: %i[green],
|
|
11
|
+
warn: %i[yellow],
|
|
12
|
+
error: %i[red],
|
|
13
|
+
fatal: %i[white bold on_red],
|
|
14
|
+
any: %i[white bold]
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
def initialize defaults: DEFAULTS, decorator: Pastel.new(enabled: $stdout.tty?)
|
|
18
|
+
@defaults = defaults
|
|
19
|
+
@decorator = decorator
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def debug(text) = decorate text, __method__
|
|
23
|
+
|
|
24
|
+
def info(text) = decorate text, __method__
|
|
25
|
+
|
|
26
|
+
def warn(text) = decorate text, __method__
|
|
27
|
+
|
|
28
|
+
def error(text) = decorate text, __method__
|
|
29
|
+
|
|
30
|
+
def fatal(text) = decorate text, __method__
|
|
31
|
+
|
|
32
|
+
def any(text) = decorate text, __method__
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
attr_reader :defaults, :decorator
|
|
37
|
+
|
|
38
|
+
def decorate(text, kind) = decorator.decorate text, *defaults.fetch(kind)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "logger"
|
|
4
|
+
require "stringio"
|
|
5
|
+
|
|
6
|
+
module Cogger
|
|
7
|
+
module Refinements
|
|
8
|
+
# Provides additional enhancements to a logger device.
|
|
9
|
+
module LogDevices
|
|
10
|
+
refine Logger::LogDevice do
|
|
11
|
+
def reread
|
|
12
|
+
case dev
|
|
13
|
+
when File then dev.class.new(dev).read
|
|
14
|
+
when StringIO then dev.tap(&:rewind).read
|
|
15
|
+
else ""
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "logger"
|
|
4
|
+
|
|
5
|
+
module Cogger
|
|
6
|
+
module Refinements
|
|
7
|
+
# Provides additional enhancements to a logger.
|
|
8
|
+
module Loggers
|
|
9
|
+
using LogDevices
|
|
10
|
+
|
|
11
|
+
refine Logger do
|
|
12
|
+
def reread = @logdev.reread
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/cogger.rb
ADDED
data.tar.gz.sig
ADDED
|
Binary file
|
metadata
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cogger
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brooke Kuhlmann
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain:
|
|
11
|
+
- |
|
|
12
|
+
-----BEGIN CERTIFICATE-----
|
|
13
|
+
MIIC/jCCAeagAwIBAgIBBTANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
|
|
14
|
+
a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMjAzMTkxNzI0MzJaFw0yMzAzMTkx
|
|
15
|
+
NzI0MzJaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
|
|
16
|
+
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6l1qpXTiomH1RfMRloyw7MiE
|
|
17
|
+
xyVx/x8Yc3EupdH7uhNaTXQGyORN6aOY//1QXXMHIZ9tW74nZLhesWMSUMYy0XhB
|
|
18
|
+
brs+KkurHnc9FnEJAbG7ebGvl/ncqZt72nQvaxpDxvuCBHgJAz+8i5wl6FhLw+oT
|
|
19
|
+
9z0A8KcGhz67SdcoQiD7qiCjL/2NTeWHOzkpPrdGlt088+VerEEGf5I13QCvaftP
|
|
20
|
+
D5vkU0YlAm1r98BymuJlcQ1qdkVEI1d48ph4kcS0S0nv1RiuyVb6TCAR3Nu3VaVq
|
|
21
|
+
3fPzZKJLZBx67UvXdbdicWPiUR75elI4PXpLIic3xytaF52ZJYyKZCNZJhNwfQID
|
|
22
|
+
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0nzow9vc
|
|
23
|
+
2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAJbbNyWzFjqUNVPPCUCo
|
|
24
|
+
IMrhDa9xf1xkORXNYYbmXgoxRy/KyNbUr+jgEEoWJAm9GXlcqxxWAUI6pK/i4/Qi
|
|
25
|
+
X6rPFEFmeObDOHNvuqy8Hd6AYsu+kP94U/KJhe9wnWGMmGoNKJNU3EkW3jM/osSl
|
|
26
|
+
+JRxiH5t4WtnDiVyoYl5nYC02rYdjJkG6VMxDymXTqn7u6HhYgZkGujq1UPar8x2
|
|
27
|
+
hNIWJblDKKSu7hA2d6+kUthuYo13o1sg1Da/AEDg0hoZSUvhqDEF5Hy232qb3pDt
|
|
28
|
+
CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
|
|
29
|
+
RFE=
|
|
30
|
+
-----END CERTIFICATE-----
|
|
31
|
+
date: 2022-04-03 00:00:00.000000000 Z
|
|
32
|
+
dependencies:
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: pastel
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0.8'
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0.8'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: zeitwerk
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '2.5'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '2.5'
|
|
61
|
+
description:
|
|
62
|
+
email:
|
|
63
|
+
- brooke@alchemists.io
|
|
64
|
+
executables: []
|
|
65
|
+
extensions: []
|
|
66
|
+
extra_rdoc_files:
|
|
67
|
+
- README.adoc
|
|
68
|
+
- LICENSE.adoc
|
|
69
|
+
files:
|
|
70
|
+
- LICENSE.adoc
|
|
71
|
+
- README.adoc
|
|
72
|
+
- cogger.gemspec
|
|
73
|
+
- lib/cogger.rb
|
|
74
|
+
- lib/cogger/client.rb
|
|
75
|
+
- lib/cogger/color.rb
|
|
76
|
+
- lib/cogger/refinements/log_devices.rb
|
|
77
|
+
- lib/cogger/refinements/loggers.rb
|
|
78
|
+
homepage: https://www.alchemists.io/projects/cogger
|
|
79
|
+
licenses:
|
|
80
|
+
- Hippocratic-2.1
|
|
81
|
+
metadata:
|
|
82
|
+
bug_tracker_uri: https://github.com/bkuhlmann/cogger/issues
|
|
83
|
+
changelog_uri: https://www.alchemists.io/projects/cogger/versions
|
|
84
|
+
documentation_uri: https://www.alchemists.io/projects/cogger
|
|
85
|
+
label: Cogger
|
|
86
|
+
rubygems_mfa_required: 'true'
|
|
87
|
+
source_code_uri: https://github.com/bkuhlmann/cogger
|
|
88
|
+
post_install_message:
|
|
89
|
+
rdoc_options: []
|
|
90
|
+
require_paths:
|
|
91
|
+
- lib
|
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.1'
|
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
requirements: []
|
|
103
|
+
rubygems_version: 3.3.10
|
|
104
|
+
signing_key:
|
|
105
|
+
specification_version: 4
|
|
106
|
+
summary: Decorates native logging with colorized output.
|
|
107
|
+
test_files: []
|
metadata.gz.sig
ADDED
|
Binary file
|