json_ruby_logger 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.pre-commit-config.yaml +32 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +205 -0
- data/Rakefile +12 -0
- data/json_ruby_logger.gemspec +41 -0
- data/lib/json_ruby_logger/version.rb +5 -0
- data/lib/json_ruby_logger.rb +39 -0
- data/sig/json_ruby_logger.rbs +4 -0
- metadata +105 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d54a10d53e83e69e49606a42420dea9540cfd30c078afe1a9b34b6ae2640380a
|
|
4
|
+
data.tar.gz: 13b3b25e9bf946155f6ffcfacb57b07c9ae0926af755da273fd1647683f3b95f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e3b15e905b9fbfa963f1d822d1d583ba32649dc0c67a778b237ce557e90e7ce651bbe03e011aa3a52c3705c02412e73249c4bc3ea729fe33738a90f8c7179374
|
|
7
|
+
data.tar.gz: 76593234c12c2fc24215dc722665e7a972e24eff331b3cecc90ad582594f1b02ded2b9edac7df313d857c18b52295e29d2b3ea422c2a7c5e1f4345195fe6c502
|
data/.editorconfig
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# See https://pre-commit.com for more information
|
|
2
|
+
# See https://pre-commit.com/hooks.html for more hooks
|
|
3
|
+
repos:
|
|
4
|
+
- repo: https://github.com/gitleaks/gitleaks
|
|
5
|
+
rev: v8.16.1
|
|
6
|
+
hooks:
|
|
7
|
+
- id: gitleaks
|
|
8
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
9
|
+
rev: v3.2.0
|
|
10
|
+
hooks:
|
|
11
|
+
# - id: no-commit-to-branch
|
|
12
|
+
# args: ['--branch', 'main']
|
|
13
|
+
- id: trailing-whitespace
|
|
14
|
+
- id: end-of-file-fixer
|
|
15
|
+
- id: check-yaml
|
|
16
|
+
- id: check-json
|
|
17
|
+
- id: check-added-large-files
|
|
18
|
+
- id: detect-private-key
|
|
19
|
+
- id: check-executables-have-shebangs
|
|
20
|
+
- id: check-merge-conflict
|
|
21
|
+
- id: mixed-line-ending
|
|
22
|
+
args:
|
|
23
|
+
- "--fix=lf"
|
|
24
|
+
- id: pretty-format-json
|
|
25
|
+
args:
|
|
26
|
+
- "--autofix"
|
|
27
|
+
- "--indent=4"
|
|
28
|
+
- "--no-sort-keys"
|
|
29
|
+
- repo: https://github.com/mattlqx/pre-commit-ruby
|
|
30
|
+
rev: v1.3.5
|
|
31
|
+
hooks:
|
|
32
|
+
- id: rubocop
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-performance
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
TargetRubyVersion: <%= RUBY_VERSION[/^\d+\.\d+/, 0] %>
|
|
6
|
+
|
|
7
|
+
# Disable all cops for now. Only notify on DeprecatedClassMethods
|
|
8
|
+
DisabledByDefault: true
|
|
9
|
+
Layout/LineLength:
|
|
10
|
+
Max: 300
|
|
11
|
+
|
|
12
|
+
Lint/DeprecatedClassMethods:
|
|
13
|
+
Enabled: true
|
|
14
|
+
Style/StringLiterals:
|
|
15
|
+
Enabled: true
|
|
16
|
+
|
|
17
|
+
Style/HashSyntax:
|
|
18
|
+
Enabled: false
|
|
19
|
+
Style/GuardClause:
|
|
20
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
json_ruby_logger (0.1.5)
|
|
5
|
+
json (~> 2.6)
|
|
6
|
+
logger (~> 1.5)
|
|
7
|
+
time (~> 0.2)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
ast (2.4.2)
|
|
13
|
+
date (3.3.3)
|
|
14
|
+
diff-lcs (1.5.0)
|
|
15
|
+
json (2.6.3)
|
|
16
|
+
language_server-protocol (3.17.0.3)
|
|
17
|
+
logger (1.5.3)
|
|
18
|
+
parallel (1.23.0)
|
|
19
|
+
parser (3.2.2.3)
|
|
20
|
+
ast (~> 2.4.1)
|
|
21
|
+
racc
|
|
22
|
+
racc (1.7.1)
|
|
23
|
+
rainbow (3.1.1)
|
|
24
|
+
rake (13.0.6)
|
|
25
|
+
regexp_parser (2.8.1)
|
|
26
|
+
rexml (3.2.5)
|
|
27
|
+
rspec (3.12.0)
|
|
28
|
+
rspec-core (~> 3.12.0)
|
|
29
|
+
rspec-expectations (~> 3.12.0)
|
|
30
|
+
rspec-mocks (~> 3.12.0)
|
|
31
|
+
rspec-core (3.12.2)
|
|
32
|
+
rspec-support (~> 3.12.0)
|
|
33
|
+
rspec-expectations (3.12.3)
|
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
+
rspec-support (~> 3.12.0)
|
|
36
|
+
rspec-mocks (3.12.5)
|
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
|
+
rspec-support (~> 3.12.0)
|
|
39
|
+
rspec-support (3.12.1)
|
|
40
|
+
rubocop (1.54.1)
|
|
41
|
+
json (~> 2.3)
|
|
42
|
+
language_server-protocol (>= 3.17.0)
|
|
43
|
+
parallel (~> 1.10)
|
|
44
|
+
parser (>= 3.2.2.3)
|
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
46
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
47
|
+
rexml (>= 3.2.5, < 4.0)
|
|
48
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
|
49
|
+
ruby-progressbar (~> 1.7)
|
|
50
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
51
|
+
rubocop-ast (1.29.0)
|
|
52
|
+
parser (>= 3.2.1.0)
|
|
53
|
+
ruby-progressbar (1.13.0)
|
|
54
|
+
time (0.2.2)
|
|
55
|
+
date
|
|
56
|
+
unicode-display_width (2.4.2)
|
|
57
|
+
|
|
58
|
+
PLATFORMS
|
|
59
|
+
ruby
|
|
60
|
+
|
|
61
|
+
DEPENDENCIES
|
|
62
|
+
json_ruby_logger!
|
|
63
|
+
rake (~> 13.0)
|
|
64
|
+
rspec (~> 3.0)
|
|
65
|
+
rubocop (~> 1.21)
|
|
66
|
+
|
|
67
|
+
BUNDLED WITH
|
|
68
|
+
2.4.13
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 do-i-need-a-username
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 ml
|
|
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,205 @@
|
|
|
1
|
+
# JsonRubyLogger
|
|
2
|
+
|
|
3
|
+
A simpe ruby [logger](https://ruby-doc.org/3.2.2/stdlibs/logger/Logger.html) that logs in json format with the below information.
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"date":"2023-07-06T11:59:51+10:00",
|
|
8
|
+
"file_name":"test_logging.rb",
|
|
9
|
+
"calling_class":"LogTest::TestLogging",
|
|
10
|
+
"function_name":"call",
|
|
11
|
+
"lineno":8,
|
|
12
|
+
"severity":"INFO",
|
|
13
|
+
"pid":"27365",
|
|
14
|
+
"message":"Hello World call from LogTest::TestLogging"
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
20
|
+
- [Installation](#installation)
|
|
21
|
+
- [Usage](#usage)
|
|
22
|
+
- [Examples](##examples)
|
|
23
|
+
- [Example 1 - Single file](#example-1)
|
|
24
|
+
- [Example 2 - Multiple files file](#example-2)
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
gem install:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
gem install json_ruby_logger
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
bundler install:
|
|
35
|
+
|
|
36
|
+
```Gemfile
|
|
37
|
+
gem 'json_ruby_logger'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Examples
|
|
43
|
+
|
|
44
|
+
#### Example 1
|
|
45
|
+
|
|
46
|
+
Example 1 - Single function in a single file called `test_logging.rb`:
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
include Logging
|
|
51
|
+
def test
|
|
52
|
+
logger.info { "Hello World call from #{self.class.name}" }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Run `ruby test_logging.rb`
|
|
59
|
+
|
|
60
|
+
Output from example 1:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{"date":"2023-07-06T15:10:24+10:00","file_name":"test_logger.rb","calling_class":"Object","function_name":"test","lineno":31,"severity":"INFO","pid":44665,"message":"Hello World call from Object"}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Example 2 in a single files called `test_logging.rb`:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
require 'json_ruby_logger'
|
|
70
|
+
|
|
71
|
+
module LogTest
|
|
72
|
+
class TestLogging
|
|
73
|
+
include JsonRubyLogger
|
|
74
|
+
|
|
75
|
+
def call
|
|
76
|
+
logger.info { "Hello World call from #{self.class.name}" }
|
|
77
|
+
call2
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def call2
|
|
81
|
+
logger.info { "Hello World call2 from #{self.class.name}" }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class TestLogging2
|
|
88
|
+
include JsonRubyLogger
|
|
89
|
+
|
|
90
|
+
def call
|
|
91
|
+
logger.info { "Hello World call from #{self.class.name}" }
|
|
92
|
+
call2
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def call2
|
|
96
|
+
logger.info { "Hello World call2 from #{self.class.name}" }
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
LogTest::TestLogging.new.call
|
|
101
|
+
TestLogging2.new.call
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Run `ruby test_logging.rb`
|
|
105
|
+
|
|
106
|
+
Output from example 2:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{"date":"2023-07-06T11:59:51+10:00","file_name":"test_logging.rb","calling_class":"LogTest::TestLogging","function_name":"call","lineno":8,"severity":"INFO","pid":"#27365","message":"Hello World call from LogTest::TestLogging"}
|
|
110
|
+
{"date":"2023-07-06T11:59:51+10:00","file_name":"test_logging.rb","calling_class":"LogTest::TestLogging","function_name":"call2","lineno":13,"severity":"INFO","pid":"#27365","message":"Hello World call2 from LogTest::TestLogging"}
|
|
111
|
+
{"date":"2023-07-06T11:59:51+10:00","file_name":"test_logging.rb","calling_class":"TestLogging2","function_name":"call","lineno":23,"severity":"INFO","pid":"#27365","message":"Hello World call from TestLogging2"}
|
|
112
|
+
{"date":"2023-07-06T11:59:51+10:00","file_name":"test_logging.rb","calling_class":"TestLogging2","function_name":"call2","lineno":28,"severity":"INFO","pid":"#27365","message":"Hello World call2 from TestLogging2"}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Example 3
|
|
116
|
+
|
|
117
|
+
Example 3 multi files in sub folders:
|
|
118
|
+
|
|
119
|
+
File `./lib/another_class.rb`
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
require 'json_ruby_logger'
|
|
123
|
+
|
|
124
|
+
class AnotherClass
|
|
125
|
+
include JsonRubyLogger
|
|
126
|
+
|
|
127
|
+
def another_class_call
|
|
128
|
+
logger.info { "AnotherClass Hello World call from #{self.class.name}" }
|
|
129
|
+
another_class
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def another_class
|
|
133
|
+
logger.info { "Hello World call2 from #{self.class.name}" }
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
File `./test_logging.rb`
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
141
|
+
require_relative 'lib/another_class'
|
|
142
|
+
require 'json_ruby_logger'
|
|
143
|
+
|
|
144
|
+
class TestLogging
|
|
145
|
+
include JsonRubyLogger
|
|
146
|
+
|
|
147
|
+
def call
|
|
148
|
+
logger.info { "Hello World call from #{self.class.name}" }
|
|
149
|
+
another_class
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def another_class
|
|
153
|
+
logger.info { "Hello World call2 from #{self.class.name}" }
|
|
154
|
+
AnotherClass.new.another_class_call
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
TestLogging.new.call
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Run `ruby test_logging.rb`
|
|
162
|
+
|
|
163
|
+
Output from example 3:
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{"date":"2023-07-06T12:08:48+10:00","file_name":"test_logger.rb","calling_class":"TestLogging","function_name":"call","lineno":8,"severity":"INFO","pid":"#29554","message":"Hello World call from TestLogging"}
|
|
167
|
+
{"date":"2023-07-06T12:08:48+10:00","file_name":"test_logger.rb","calling_class":"TestLogging","function_name":"another_class","lineno":13,"severity":"INFO","pid":"#29554","message":"Hello World call2 from TestLogging"}
|
|
168
|
+
{"date":"2023-07-06T12:08:48+10:00","file_name":"another_class.rb","calling_class":"AnotherClass","function_name":"another_class_call","lineno":7,"severity":"INFO","pid":"#29554","message":"AnotherClass Hello World call from AnotherClass"}
|
|
169
|
+
{"date":"2023-07-06T12:08:48+10:00","file_name":"another_class.rb","calling_class":"AnotherClass","function_name":"another_class","lineno":12,"severity":"INFO","pid":"#29554","message":"Hello World call2 from AnotherClass"}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
175
|
+
|
|
176
|
+
## Creating a Gem
|
|
177
|
+
|
|
178
|
+
### Create a Gem Skeleton
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
bundle gem json_ruby_logger \
|
|
182
|
+
--mit \
|
|
183
|
+
--linter=rubocop \
|
|
184
|
+
--test=rspec \
|
|
185
|
+
--ci=github \
|
|
186
|
+
--no-coc
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Build the gem
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
gem build json_ruby_logger.gemspec
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### push the gem to rubygems.org
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
gem push json_ruby_logger-0.1.0.gem
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Revoke/yank a gem
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
gem yank json_ruby_logger -v 0.1.0
|
|
205
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/json_ruby_logger/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "json_ruby_logger"
|
|
7
|
+
spec.version = JsonRubyLogger::VERSION
|
|
8
|
+
spec.authors = ["ml"]
|
|
9
|
+
spec.email = ["redacted@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Simple JSON logging for Ruby, including classnames, filenames, linenos, timestamps, and log levels."
|
|
12
|
+
spec.description = "Simple JSON logging for Ruby"
|
|
13
|
+
spec.homepage = "https://github.com/do-i-need-a-username/json_ruby_logger"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
21
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .github .circleci appveyor])
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
# Uncomment to register a new dependency of your gem
|
|
35
|
+
spec.add_dependency 'logger', '~> 1.5'
|
|
36
|
+
spec.add_dependency 'json', '~> 2.6'
|
|
37
|
+
spec.add_dependency 'time', '~> 0.2'
|
|
38
|
+
|
|
39
|
+
# For more information and examples about making a new gem, check out our
|
|
40
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
41
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'logger'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'time'
|
|
5
|
+
|
|
6
|
+
require_relative "json_ruby_logger/version"
|
|
7
|
+
|
|
8
|
+
module JsonRubyLogger
|
|
9
|
+
class Error < StandardError; end
|
|
10
|
+
# Your code goes here...
|
|
11
|
+
|
|
12
|
+
# This is the magical bit that gets mixed into your classes
|
|
13
|
+
def logger
|
|
14
|
+
# caller_locations returns an array of Thread::Backtrace::Location
|
|
15
|
+
JsonRubyLogger.logger(self.class.name, caller_locations.first)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Global, memoized, lazy initialised instance of a logger
|
|
19
|
+
def self.logger(calling_class, caller_info)
|
|
20
|
+
logger = Logger.new(STDOUT)
|
|
21
|
+
|
|
22
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
|
23
|
+
date_format = datetime.iso8601
|
|
24
|
+
JSON.dump(
|
|
25
|
+
date: date_format,
|
|
26
|
+
file_name: caller_info.path.split('/').last,
|
|
27
|
+
calling_class: calling_class,
|
|
28
|
+
function_name: caller_info.label.split(' ').last,
|
|
29
|
+
lineno: caller_info.lineno,
|
|
30
|
+
severity: severity,
|
|
31
|
+
pid: Process.pid,
|
|
32
|
+
message: msg
|
|
33
|
+
) + "\n"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
logger.level = ENV.fetch('LOG_LEVEL', 'INFO').upcase
|
|
37
|
+
logger
|
|
38
|
+
end
|
|
39
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: json_ruby_logger
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.5
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ml
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-07-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: logger
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.5'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.5'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: json
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.6'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.6'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: time
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.2'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.2'
|
|
55
|
+
description: Simple JSON logging for Ruby
|
|
56
|
+
email:
|
|
57
|
+
- redacted@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".editorconfig"
|
|
63
|
+
- ".pre-commit-config.yaml"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".rubocop.yml"
|
|
66
|
+
- CHANGELOG.md
|
|
67
|
+
- Gemfile
|
|
68
|
+
- Gemfile.lock
|
|
69
|
+
- LICENSE
|
|
70
|
+
- LICENSE.txt
|
|
71
|
+
- README.md
|
|
72
|
+
- Rakefile
|
|
73
|
+
- json_ruby_logger.gemspec
|
|
74
|
+
- lib/json_ruby_logger.rb
|
|
75
|
+
- lib/json_ruby_logger/version.rb
|
|
76
|
+
- sig/json_ruby_logger.rbs
|
|
77
|
+
homepage: https://github.com/do-i-need-a-username/json_ruby_logger
|
|
78
|
+
licenses:
|
|
79
|
+
- MIT
|
|
80
|
+
metadata:
|
|
81
|
+
allowed_push_host: https://rubygems.org
|
|
82
|
+
homepage_uri: https://github.com/do-i-need-a-username/json_ruby_logger
|
|
83
|
+
source_code_uri: https://github.com/do-i-need-a-username/json_ruby_logger
|
|
84
|
+
changelog_uri: https://github.com/do-i-need-a-username/json_ruby_logger
|
|
85
|
+
post_install_message:
|
|
86
|
+
rdoc_options: []
|
|
87
|
+
require_paths:
|
|
88
|
+
- lib
|
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: 2.6.0
|
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
|
+
requirements:
|
|
96
|
+
- - ">="
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: '0'
|
|
99
|
+
requirements: []
|
|
100
|
+
rubygems_version: 3.4.13
|
|
101
|
+
signing_key:
|
|
102
|
+
specification_version: 4
|
|
103
|
+
summary: Simple JSON logging for Ruby, including classnames, filenames, linenos, timestamps,
|
|
104
|
+
and log levels.
|
|
105
|
+
test_files: []
|