logger_json 1.0.1 → 1.0.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/.gitignore +1 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +38 -0
- data/MIT-LICENSE +1 -0
- data/README.md +73 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/logger_json/json/debug.rb +9 -0
- data/lib/logger_json/json/error.rb +9 -0
- data/lib/logger_json/json/fatal.rb +9 -0
- data/lib/logger_json/json/info.rb +9 -0
- data/lib/logger_json/json/model.rb +50 -0
- data/lib/logger_json/json/warn.rb +9 -0
- data/lib/logger_json/logger.rb +21 -0
- data/lib/logger_json/text.rb +6 -0
- data/lib/logger_json/version.rb +3 -0
- data/lib/logger_json/writter.rb +8 -0
- data/logger_json.gemspec +30 -0
- metadata +66 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d77ed01ffa4b6b2efca7dc90bf13728c8c55c9610657c1dee14e0aa8d75429f3
|
4
|
+
data.tar.gz: 3050046c3bb5c23dc8d78dc9ed99358f1e326ac838fa3cf9299906ce6a2a439a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0cbead5a1bc8c32cb7b80e9119d113491cb38ccbf6eba8a0619e776bb3173da0ceb8f7b9dbea8e104cac9b3e7c9ecbe903f355d134282e028f1769798fef032
|
7
|
+
data.tar.gz: c4d2e187fda88afca2144740298e8c348e304e3e3e3b05f0092ee191fce4c753784107970f7f8f8d9de33e5d3a37f087828509880f46ec99213a061b2ffd5603
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/logs
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.4.0)
|
5
|
+
coderay (1.1.2)
|
6
|
+
jaro_winkler (1.5.4)
|
7
|
+
method_source (0.9.2)
|
8
|
+
minitest (5.14.0)
|
9
|
+
parallel (1.19.1)
|
10
|
+
parser (2.7.0.2)
|
11
|
+
ast (~> 2.4.0)
|
12
|
+
pry (0.12.2)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.9.0)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rubocop (0.79.0)
|
17
|
+
jaro_winkler (~> 1.5.1)
|
18
|
+
parallel (~> 1.10)
|
19
|
+
parser (>= 2.7.0.1)
|
20
|
+
rainbow (>= 2.2.2, < 4.0)
|
21
|
+
ruby-progressbar (~> 1.7)
|
22
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
23
|
+
ruby-progressbar (1.10.1)
|
24
|
+
unicode-display_width (1.6.1)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
minitest
|
31
|
+
pry (~> 0.12.2)
|
32
|
+
rubocop
|
33
|
+
|
34
|
+
RUBY VERSION
|
35
|
+
ruby 2.4.9p362
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.17.3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Copyright 2020 .
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
**LoggerJson** is a gem written in Ruby that adds new functionality, without changing the function of the Logger class methods, which creates the logs in the json format.
|
2
|
+
|
3
|
+
**Getting started**
|
4
|
+
|
5
|
+
LoggerJson's installation is pretty standard:
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install logger_json
|
9
|
+
```
|
10
|
+
|
11
|
+
Add the following line to your `Gemfile`:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'logger_json'
|
15
|
+
```
|
16
|
+
|
17
|
+
Then run `bundle install`
|
18
|
+
|
19
|
+
Just initialize the gem and watch the magic happen
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'logger_json'
|
23
|
+
```
|
24
|
+
|
25
|
+
**Parameters**
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
{
|
29
|
+
date: "2020-02-05T13:46:11.026134758+00:00", #iso8601
|
30
|
+
host: "https://www.r7.com/",
|
31
|
+
thread: 'current_thread',
|
32
|
+
methods: ['create_json'],
|
33
|
+
level: 'info',
|
34
|
+
message: 'LoggerJson is a gem written in Ruby that ...'
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
**To add parameters in the json logger**
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
more_params = {key1: data, key2: data ... keyN: data}
|
42
|
+
Logger.new('output').warn(message, more_params)
|
43
|
+
```
|
44
|
+
|
45
|
+
**Compatibility**
|
46
|
+
|
47
|
+
- Ruby 1.9+
|
48
|
+
|
49
|
+
**Running tests**
|
50
|
+
|
51
|
+
LoggerJson uses [Mini Test](https://github.com/seattlerb/minitest) as test framework.
|
52
|
+
|
53
|
+
* Ruby version > 2.0
|
54
|
+
|
55
|
+
* Running all tests:
|
56
|
+
|
57
|
+
```bash
|
58
|
+
ruby test/test.rb
|
59
|
+
```
|
60
|
+
|
61
|
+
* Runnin tests for an specific file:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
ruby test/create_file_spec.rb
|
65
|
+
```
|
66
|
+
|
67
|
+
**Changelog**
|
68
|
+
|
69
|
+
LoggerJson changelog is available [here](https://gitlab.ir7.com.br/r7/logger-json/blob/master/CHANGELOG.md).
|
70
|
+
|
71
|
+
**Copyright**
|
72
|
+
|
73
|
+
Copyright (c) 2020
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "logger_json"
|
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
@@ -0,0 +1,50 @@
|
|
1
|
+
module LoggerJson
|
2
|
+
class Model
|
3
|
+
attr_accessor :json
|
4
|
+
|
5
|
+
def initialize(message, type)
|
6
|
+
@type = type
|
7
|
+
@json = convert_to_json message
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def convert_to_json(msg)
|
13
|
+
return log(msg[0]).to_json if msg[1].nil?
|
14
|
+
return (log(msg[0]).merge(msg[1])).to_json if msg[1].is_a? Hash
|
15
|
+
return add_array_in_log msg if msg[1].is_a? Array
|
16
|
+
add_string_in_log msg
|
17
|
+
end
|
18
|
+
|
19
|
+
def log(message)
|
20
|
+
{
|
21
|
+
date: DateTime.now.iso8601(9),
|
22
|
+
host: IO.popen('hostname').readlines[0].strip,
|
23
|
+
thread: Thread.current,
|
24
|
+
methods: methods,
|
25
|
+
level: @type,
|
26
|
+
message: message
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_array_in_log(msg)
|
31
|
+
logs = log msg[0]
|
32
|
+
msg[1].select.with_index {|val, index| logs[index] = val}
|
33
|
+
logs.to_json
|
34
|
+
end
|
35
|
+
|
36
|
+
def methods
|
37
|
+
array = []
|
38
|
+
caller.join('\n').scan(/\`([a-z_-]*)\'/) do |match|
|
39
|
+
array << match[0] unless array.include? match[0]
|
40
|
+
end
|
41
|
+
array
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_string_in_log(msg)
|
45
|
+
logs = log msg[0]
|
46
|
+
logs[:log] = msg[1]
|
47
|
+
logs.to_json
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Logger
|
2
|
+
class << self
|
3
|
+
def json_path
|
4
|
+
LoggerJson::Text::PATH
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def create_file(message, type=:info)
|
11
|
+
path = filename || Logger.json_path
|
12
|
+
json = LoggerJson::Model.new(message, type).json
|
13
|
+
LoggerJson::Writter.logger_json(path, json)
|
14
|
+
end
|
15
|
+
|
16
|
+
def filename
|
17
|
+
path = instance_variable_get("@logdev").filename
|
18
|
+
return if path.nil?
|
19
|
+
path.gsub(".log","-json.log")
|
20
|
+
end
|
21
|
+
end
|
data/logger_json.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib = File.expand_path("../lib", __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require "logger_json/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "logger_json"
|
10
|
+
spec.version = LoggerJson::VERSION.dup
|
11
|
+
spec.authors = ["Vinicius Freire"]
|
12
|
+
spec.email = ["vfoliveira@rederecord.com.br"]
|
13
|
+
|
14
|
+
spec.summary = "Flexible Json Logger solution for Ruby"
|
15
|
+
spec.description = "LoggerJson is a gem written in Ruby that adds new functionality, without changing the function of the Logger class methods, which creates the logs in the json format."
|
16
|
+
spec.homepage = "https://gitlab.ir7.com.br/r7/logger-json"
|
17
|
+
spec.license = "MIT"
|
18
|
+
spec.required_ruby_version = '>= 1.9.0'
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
CHANGED
@@ -1,24 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logger_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinicius Freire
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-02-05 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
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'
|
13
55
|
description: LoggerJson is a gem written in Ruby that adds new functionality, without
|
14
56
|
changing the function of the Logger class methods, which creates the logs in the
|
15
57
|
json format.
|
16
|
-
email:
|
58
|
+
email:
|
59
|
+
- vfoliveira@rederecord.com.br
|
17
60
|
executables: []
|
18
61
|
extensions: []
|
19
62
|
extra_rdoc_files: []
|
20
63
|
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- MIT-LICENSE
|
69
|
+
- README.md
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
21
72
|
- lib/logger_json.rb
|
73
|
+
- lib/logger_json/json/debug.rb
|
74
|
+
- lib/logger_json/json/error.rb
|
75
|
+
- lib/logger_json/json/fatal.rb
|
76
|
+
- lib/logger_json/json/info.rb
|
77
|
+
- lib/logger_json/json/model.rb
|
78
|
+
- lib/logger_json/json/warn.rb
|
79
|
+
- lib/logger_json/logger.rb
|
80
|
+
- lib/logger_json/text.rb
|
81
|
+
- lib/logger_json/version.rb
|
82
|
+
- lib/logger_json/writter.rb
|
83
|
+
- logger_json.gemspec
|
22
84
|
homepage: https://gitlab.ir7.com.br/r7/logger-json
|
23
85
|
licenses:
|
24
86
|
- MIT
|