rt-logman 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +100 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.txt +21 -0
- data/README.md +187 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config.reek +16 -0
- data/lib/logman/version.rb +3 -0
- data/lib/logman.rb +69 -0
- data/logman.gemspec +33 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0fd4713e9ae89962d5c9d63dce15c9592b66c0e
|
4
|
+
data.tar.gz: bcc046ddbbb50f4563e7ad6f7687a7f923b8014f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '03663528dfe5ab510667cc91966da0776c0b847ce0ac5936b319d774bf6d57fd0e31c8ed67bc070969ac9e571979b35896cafd100478b2adf5a332bf9c406c9c'
|
7
|
+
data.tar.gz: 295666771e628e232c630d1a8dde906029213f7b0b7895e03ba31a5e2cadf1ee7a42d8e04d831d7b6ea0468d2acee1f45675932c6c58ec3e00b831bd5151545c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
DisplayCopNames: true
|
5
|
+
|
6
|
+
Exclude:
|
7
|
+
- "*.gemspec"
|
8
|
+
- "vendor/**/*"
|
9
|
+
|
10
|
+
Style/StringLiterals:
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Style/StringLiteralsInInterpolation:
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Style/NumericLiterals:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/HashSyntax:
|
23
|
+
EnforcedStyle: hash_rockets
|
24
|
+
|
25
|
+
Style/CollectionMethods:
|
26
|
+
StyleGuide: "https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size"
|
27
|
+
Enabled: true
|
28
|
+
|
29
|
+
Metrics/LineLength:
|
30
|
+
Max: 120
|
31
|
+
|
32
|
+
Style/EmptyLinesAroundClassBody:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/EmptyLinesAroundModuleBody:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/MultilineMethodCallIndentation:
|
39
|
+
EnforcedStyle: indented
|
40
|
+
IndentationWidth: 2
|
41
|
+
|
42
|
+
Style/SpecialGlobalVars:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/PercentLiteralDelimiters:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
RSpec/InstanceVariable:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
RSpec/MultipleExpectations:
|
52
|
+
Max: 5
|
53
|
+
|
54
|
+
Metrics/BlockLength:
|
55
|
+
Exclude:
|
56
|
+
- "Rakefile"
|
57
|
+
- "**/*.rake"
|
58
|
+
- "spec/**/*.rb"
|
59
|
+
|
60
|
+
Style/EmptyLinesAroundBlockBody:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
RSpec/BeforeAfterAll:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
RSpec/ExampleLength:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
RSpec/DescribedClass:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/IndentArray:
|
73
|
+
EnforcedStyle: consistent
|
74
|
+
|
75
|
+
Style/MultilineMethodCallBraceLayout:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
RSpec/MessageSpies:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
Style/MultilineBlockLayout:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
RSpec/SubjectStub:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
RSpec/DescribeClass:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
RSpec/LeadingSubject:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
Style/WordArray:
|
94
|
+
Enabled: false
|
95
|
+
|
96
|
+
RSpec/NotToNot:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
Metrics/MethodLength:
|
100
|
+
Enabled: false
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at igor@renderedtext.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rt-logman (0.9.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.3.0)
|
10
|
+
axiom-types (0.1.1)
|
11
|
+
descendants_tracker (~> 0.0.4)
|
12
|
+
ice_nine (~> 0.11.0)
|
13
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
14
|
+
codeclimate-engine-rb (0.4.1)
|
15
|
+
virtus (~> 1.0)
|
16
|
+
coercible (1.0.0)
|
17
|
+
descendants_tracker (~> 0.0.1)
|
18
|
+
descendants_tracker (0.0.4)
|
19
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
docile (1.1.5)
|
22
|
+
equalizer (0.0.11)
|
23
|
+
ice_nine (0.11.2)
|
24
|
+
json (2.1.0)
|
25
|
+
parallel (1.12.0)
|
26
|
+
parser (2.4.0.2)
|
27
|
+
ast (~> 2.3)
|
28
|
+
powerpack (0.1.1)
|
29
|
+
rainbow (2.2.2)
|
30
|
+
rake
|
31
|
+
rake (10.5.0)
|
32
|
+
reek (4.7.3)
|
33
|
+
codeclimate-engine-rb (~> 0.4.0)
|
34
|
+
parser (>= 2.4.0.0, < 2.5)
|
35
|
+
rainbow (~> 2.0)
|
36
|
+
rspec (3.7.0)
|
37
|
+
rspec-core (~> 3.7.0)
|
38
|
+
rspec-expectations (~> 3.7.0)
|
39
|
+
rspec-mocks (~> 3.7.0)
|
40
|
+
rspec-core (3.7.0)
|
41
|
+
rspec-support (~> 3.7.0)
|
42
|
+
rspec-expectations (3.7.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.7.0)
|
45
|
+
rspec-mocks (3.7.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.7.0)
|
48
|
+
rspec-support (3.7.0)
|
49
|
+
rubocop (0.51.0)
|
50
|
+
parallel (~> 1.10)
|
51
|
+
parser (>= 2.3.3.1, < 3.0)
|
52
|
+
powerpack (~> 0.1)
|
53
|
+
rainbow (>= 2.2.2, < 3.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
56
|
+
rubocop-rspec (1.20.1)
|
57
|
+
rubocop (>= 0.51.0)
|
58
|
+
ruby-progressbar (1.9.0)
|
59
|
+
simplecov (0.15.1)
|
60
|
+
docile (~> 1.1.0)
|
61
|
+
json (>= 1.8, < 3)
|
62
|
+
simplecov-html (~> 0.10.0)
|
63
|
+
simplecov-html (0.10.2)
|
64
|
+
thread_safe (0.3.6)
|
65
|
+
timecop (0.9.1)
|
66
|
+
unicode-display_width (1.3.0)
|
67
|
+
virtus (1.0.5)
|
68
|
+
axiom-types (~> 0.1)
|
69
|
+
coercible (~> 1.0)
|
70
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
71
|
+
equalizer (~> 0.0, >= 0.0.9)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
ruby
|
75
|
+
|
76
|
+
DEPENDENCIES
|
77
|
+
bundler (~> 1.16)
|
78
|
+
rake (~> 10.0)
|
79
|
+
reek (~> 4.5)
|
80
|
+
rspec (~> 3.0)
|
81
|
+
rt-logman!
|
82
|
+
rubocop (~> 0.47)
|
83
|
+
rubocop-rspec (~> 1.13)
|
84
|
+
simplecov (~> 0.13)
|
85
|
+
timecop (~> 0.9)
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Igor Šarčević
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
# Logman
|
2
|
+
|
3
|
+
[![Build Status](https://semaphoreci.com/api/v1/renderedtext/logman/branches/master/badge.svg)](https://semaphoreci.com/renderedtext/logman)
|
4
|
+
|
5
|
+
Logman introduces a unified logging format in your project. Every log line is an
|
6
|
+
*event* that is logged to the STDOUT or to file.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "rt-logman"
|
14
|
+
```
|
15
|
+
|
16
|
+
## Basic Usage
|
17
|
+
|
18
|
+
To log an informative message to STDOUT, use the following code snippet:
|
19
|
+
|
20
|
+
``` ruby
|
21
|
+
Logman.info("Hello World")
|
22
|
+
|
23
|
+
# Output:
|
24
|
+
# level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='Hello World'
|
25
|
+
```
|
26
|
+
|
27
|
+
Every log event can be extended with metadata — a hash with key value pairs:
|
28
|
+
|
29
|
+
``` ruby
|
30
|
+
Logman.info("Hello World", :from => "renderedtext", :to => "The World")
|
31
|
+
|
32
|
+
# Output:
|
33
|
+
# level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='Hello World' from='renderedtext' to='The World'
|
34
|
+
```
|
35
|
+
|
36
|
+
Every log event has a severity. In the previous examples we have used `info`. To
|
37
|
+
log an `error` use the following snippet:
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
Logman.error("Team does not exists", :owner => "renderedtext", :team_name => "z-fightes")
|
41
|
+
|
42
|
+
# Output:
|
43
|
+
# level='E' time='2017-12-11 09:47:27 +0000' pid='1234' event='Team does not exists' owner='renderedtext' team_name='z-fighters'
|
44
|
+
```
|
45
|
+
|
46
|
+
Logman supports multiple severity levels:
|
47
|
+
|
48
|
+
``` ruby
|
49
|
+
Logman.fatal("Hello")
|
50
|
+
Logman.error("Hello")
|
51
|
+
Logman.warn("Hello")
|
52
|
+
Logman.info("Hello")
|
53
|
+
Logman.debug("Hello")
|
54
|
+
```
|
55
|
+
|
56
|
+
Where the following hierarchy stands:
|
57
|
+
|
58
|
+
``` txt
|
59
|
+
FATAL > ERROR > WARN > INFO > DEBUG
|
60
|
+
```
|
61
|
+
|
62
|
+
## Instantiated Loggers
|
63
|
+
|
64
|
+
Logs in a class or system component usually share common metadata fields. For
|
65
|
+
this purpose, an new instance of Logman can be created and pre-populated with
|
66
|
+
metadata.
|
67
|
+
|
68
|
+
In the following example, we will add logs to a video processor:
|
69
|
+
|
70
|
+
``` ruby
|
71
|
+
class VideoProcessor
|
72
|
+
|
73
|
+
def initialize(video)
|
74
|
+
@logger = Logman.new
|
75
|
+
|
76
|
+
# these fields will appear in every log event
|
77
|
+
@logger.add(:compoent => "video_processor")
|
78
|
+
@logger.add(:id => @video.id)
|
79
|
+
@logger.add(:title => "Keyboard Cat")
|
80
|
+
end
|
81
|
+
|
82
|
+
def process
|
83
|
+
@logger.info("started")
|
84
|
+
|
85
|
+
content = load_from_disk(@video.location)
|
86
|
+
@logger.info("loaded into memory", :size => content.length)
|
87
|
+
|
88
|
+
compressed_content = compress(@video)
|
89
|
+
@logger.info("compressed", :size => compressed_content.length)
|
90
|
+
|
91
|
+
s3_path = upload_to_s3(@video)
|
92
|
+
@logger.info("uploaded to S3", :s3_path => s3_path
|
93
|
+
|
94
|
+
@video.update(:s3_path => s3_path)
|
95
|
+
|
96
|
+
@logger.info("finished")
|
97
|
+
rescue => exception
|
98
|
+
@logger.error("failed", :message => exception.message)
|
99
|
+
|
100
|
+
raise
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
In case of a successful processing of a video, we would see the following:
|
107
|
+
|
108
|
+
``` txt
|
109
|
+
level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='started' id='31312' title='Keyboard Cat' component='video_processor'
|
110
|
+
level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='loaded into memory' component='video_processor' id='31312' title='Keyboard Cat' size='3123131312'
|
111
|
+
level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='compressed' component='video_processor' id='31312' title='Keyboard Cat' size='12312312'
|
112
|
+
level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='upload_to_s3' component='video_processor' id='31312' title='Keyboard Cat' s3_path='s3://random'
|
113
|
+
level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='finished' component='video_processor' id='31312' title='Keyboard Cat'
|
114
|
+
```
|
115
|
+
|
116
|
+
In case of an error, we would see the following:
|
117
|
+
|
118
|
+
``` txt
|
119
|
+
level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='started' id='31312' title='Keyboard Cat' component='video_processor'
|
120
|
+
level='E' time='2017-12-11 09:47:27 +0000' pid='1234' event='failed' component='video_processor' id='31312' title='Keyboard Cat' message='Out of memory'
|
121
|
+
```
|
122
|
+
|
123
|
+
Logman can receive a [Ruby Logger](http://ruby-doc.org/stdlib-2.2.0/libdoc/logger/rdoc/Logger.html)
|
124
|
+
instance to handle output. This is useful if you want to log to a file.
|
125
|
+
|
126
|
+
``` ruby
|
127
|
+
@logger = Logman.new(:logger => Logger.new("/tmp/out.txt"))
|
128
|
+
|
129
|
+
@logger.info("Hello World")
|
130
|
+
|
131
|
+
# => output goes to /tmp/out.txt
|
132
|
+
```
|
133
|
+
|
134
|
+
You can also pass an instance of Rails logger:
|
135
|
+
|
136
|
+
``` ruby
|
137
|
+
@logger = Logman.new(:logger => Rails.logger)
|
138
|
+
|
139
|
+
@logger.info("Hello World")
|
140
|
+
```
|
141
|
+
|
142
|
+
Or, you can pass an instance of another Logman. This is useful if you want to
|
143
|
+
create a new Logman instance with the same fields as the previous instance:
|
144
|
+
|
145
|
+
``` ruby
|
146
|
+
@api_logger = Logman.new
|
147
|
+
@api_logger.add(:version => "v2")
|
148
|
+
|
149
|
+
@team_api_logger = Logman.new(:logger => @api_logger)
|
150
|
+
# team logger copied the `version` field
|
151
|
+
|
152
|
+
@team_api_logger.info("Hello")
|
153
|
+
|
154
|
+
# level='I' time='2017-12-11 09:47:27 +0000' pid='1234' event='Hello' version='v2'
|
155
|
+
```
|
156
|
+
|
157
|
+
## Development
|
158
|
+
|
159
|
+
After checking out the repo:
|
160
|
+
|
161
|
+
- run `bundle install` to install dependencies
|
162
|
+
- run `bundle exec rspec` to run unit specs
|
163
|
+
- run `bundle exec rubocop` to check code style
|
164
|
+
- run `bundle exec reek` to check code smells
|
165
|
+
|
166
|
+
To release a new version:
|
167
|
+
|
168
|
+
- bump the version in `lib/logman/version.rb`
|
169
|
+
- run `bundle exec rake release` to release a new version on RubyGems
|
170
|
+
|
171
|
+
## Contributing
|
172
|
+
|
173
|
+
Bug reports and pull requests are welcome on GitHub at
|
174
|
+
https://github.com/renderedtext/logman. This project is intended to be a safe,
|
175
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
176
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
177
|
+
|
178
|
+
## License
|
179
|
+
|
180
|
+
The gem is available as open source under the terms of the
|
181
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
182
|
+
|
183
|
+
## Code of Conduct
|
184
|
+
|
185
|
+
Everyone interacting in the Logman project’s codebases, issue trackers, chat
|
186
|
+
rooms and mailing lists is expected to follow the
|
187
|
+
[code of conduct](https://github.com/renderedtext/logman/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "logman"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/config.reek
ADDED
data/lib/logman.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "logman/version"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
# :reek:PrimaDonnaMethod { exclude: [clear! ] }
|
5
|
+
class Logman
|
6
|
+
SEVERITY_LEVELS = %i(fatal error warn info debug).freeze
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def default_logger
|
10
|
+
@default_logger ||= Logman.new
|
11
|
+
end
|
12
|
+
|
13
|
+
SEVERITY_LEVELS.each do |severity|
|
14
|
+
define_method(severity) { |message, metadata| default_logger.public_send(severity, message, metadata) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :fields
|
19
|
+
attr_reader :logger
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
@logger = options[:logger] || ::Logger.new(STDOUT)
|
23
|
+
|
24
|
+
if @logger.instance_of?(Logman)
|
25
|
+
# copy constructor
|
26
|
+
|
27
|
+
@fields = @logger.fields.dup
|
28
|
+
@logger = @logger.logger
|
29
|
+
else
|
30
|
+
@fields = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
@logger.formatter = formatter
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(metadata = {})
|
37
|
+
@fields.merge!(metadata)
|
38
|
+
end
|
39
|
+
|
40
|
+
def clear!
|
41
|
+
@fields = {}
|
42
|
+
end
|
43
|
+
|
44
|
+
SEVERITY_LEVELS.each do |severity|
|
45
|
+
define_method(severity) { |message, metadata| log(severity, message, metadata) }
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def log(level, message, metadata = {})
|
51
|
+
@logger.public_send(level, { :event => message }.merge(@fields).merge(metadata))
|
52
|
+
end
|
53
|
+
|
54
|
+
def formatter
|
55
|
+
proc do |severity, datetime, _progname, msg|
|
56
|
+
event = {
|
57
|
+
:level => severity[0].upcase,
|
58
|
+
:time => datetime,
|
59
|
+
:pid => Process.pid
|
60
|
+
}.merge(msg)
|
61
|
+
|
62
|
+
"#{format(event)}\n"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def format(event_hash)
|
67
|
+
event_hash.map { |key, value| "#{key}='#{value}'" }.join(" ")
|
68
|
+
end
|
69
|
+
end
|
data/logman.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "logman/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rt-logman"
|
8
|
+
spec.version = Logman::VERSION
|
9
|
+
spec.authors = ["Rendered Text"]
|
10
|
+
spec.email = ["devops@renderedtext.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Logman, formalized logging micro-abstraction}
|
13
|
+
spec.description = %q{Logman, formalized logging micro-abstraction}
|
14
|
+
spec.homepage = "https://github.com/renderedtext/logman"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency "simplecov", "~> 0.13"
|
29
|
+
spec.add_development_dependency "rubocop", "~> 0.47"
|
30
|
+
spec.add_development_dependency "rubocop-rspec", "~> 1.13"
|
31
|
+
spec.add_development_dependency "reek", "~> 4.5"
|
32
|
+
spec.add_development_dependency "timecop", "~> 0.9"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rt-logman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rendered Text
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.47'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.47'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.13'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.13'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: reek
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.5'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timecop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.9'
|
125
|
+
description: Logman, formalized logging micro-abstraction
|
126
|
+
email:
|
127
|
+
- devops@renderedtext.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- config.reek
|
144
|
+
- lib/logman.rb
|
145
|
+
- lib/logman/version.rb
|
146
|
+
- logman.gemspec
|
147
|
+
homepage: https://github.com/renderedtext/logman
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.5.2.1
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Logman, formalized logging micro-abstraction
|
171
|
+
test_files: []
|