dclog 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 372c2975c0f10052f985877816b66e9f00655e23d22eb0a42711a1c5900acd02
4
- data.tar.gz: 621591b55ce509bf61b00e9c590d5633766518ed30e0a703552b0aeb89c07922
3
+ metadata.gz: 9ec22cd08745dd9e72fcb5d9dcbd5a8778b4891a51051bd0c7c365790b55a8e1
4
+ data.tar.gz: f7120064c66f80d66ea22d35548561609771eccbbc03b15a46c640e7f6e621f6
5
5
  SHA512:
6
- metadata.gz: fc462363942b62e6ca648379d9a4bf82f9329c67a14231450e96745d4369b05a7f9794eb0075e390009a85276bb9a6fb246d300817881353daff99d79b618a3e
7
- data.tar.gz: 8e97ef06b48a428cc81af5395cbe2e412d3e0aba22621236d4739e3d4b4b1176b3bd9ce7d9f82cf647e81d3c28219fcc836f46470282e3b16ca853add68ab187
6
+ metadata.gz: b9396325d1ebfe73e11f53ea32344f170c245b97738db9047b590320210fc6cec58608800b427bcf2ac9b23f4594ccb788aaf7af20ecdb44a11a87ca06597ad8
7
+ data.tar.gz: da63e6c0e9abf1912aaed55906ab159e57c2282673f6dc520a0afcb8fb562ecfddaf794a1f45455bad2cbd6be76041fb1e68e87a3fad285b0c206f682b23b227
data/.rubocop.yml CHANGED
@@ -23,3 +23,6 @@ Metrics/BlockLength:
23
23
 
24
24
  Style/StringConcatenation:
25
25
  Enabled: false
26
+
27
+ Style/ClassAndModuleChildren:
28
+ EnforcedStyle: compact
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,92 @@
1
+ # Contributing
2
+
3
+ When contributing to this repository, please first discuss the change you wish to make via issue,
4
+ email, or any other method with the owners of this repository before making a change.
5
+
6
+ Please note we have a code of conduct, please follow it in all your interactions with the project.
7
+
8
+ ## Pull Request Process
9
+
10
+ 1. Ensure any install or build dependencies are removed before the end of the layer when doing a
11
+ build.
12
+ 2. Update the README.md with details of changes to the interface, this includes new environment
13
+ variables, exposed ports, useful file locations and container parameters.
14
+ 3. Increase the version numbers in any examples files and the README.md to the new version that this
15
+ Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
16
+ 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
17
+ do not have permission to do that, you may request the second reviewer to merge it for you.
18
+
19
+ ## Code of Conduct
20
+
21
+ ### Our Pledge
22
+
23
+ In the interest of fostering an open and welcoming environment, we as
24
+ contributors and maintainers pledge to making participation in our project and
25
+ our community a harassment-free experience for everyone, regardless of age, body
26
+ size, disability, ethnicity, gender identity and expression, level of experience,
27
+ nationality, personal appearance, race, religion, or sexual identity and
28
+ orientation.
29
+
30
+ ### Our Standards
31
+
32
+ Examples of behavior that contributes to creating a positive environment
33
+ include:
34
+
35
+ * Using welcoming and inclusive language
36
+ * Being respectful of differing viewpoints and experiences
37
+ * Gracefully accepting constructive criticism
38
+ * Focusing on what is best for the community
39
+ * Showing empathy towards other community members
40
+
41
+ Examples of unacceptable behavior by participants include:
42
+
43
+ * The use of sexualized language or imagery and unwelcome sexual attention or
44
+ advances
45
+ * Trolling, insulting/derogatory comments, and personal or political attacks
46
+ * Public or private harassment
47
+ * Publishing others' private information, such as a physical or electronic
48
+ address, without explicit permission
49
+ * Other conduct which could reasonably be considered inappropriate in a
50
+ professional setting
51
+
52
+ ### Our Responsibilities
53
+
54
+ Project maintainers are responsible for clarifying the standards of acceptable
55
+ behavior and are expected to take appropriate and fair corrective action in
56
+ response to any instances of unacceptable behavior.
57
+
58
+ Project maintainers have the right and responsibility to remove, edit, or
59
+ reject comments, commits, code, wiki edits, issues, and other contributions
60
+ that are not aligned to this Code of Conduct, or to ban temporarily or
61
+ permanently any contributor for other behaviors that they deem inappropriate,
62
+ threatening, offensive, or harmful.
63
+
64
+ ### Scope
65
+
66
+ This Code of Conduct applies both within project spaces and in public spaces
67
+ when an individual is representing the project or its community. Examples of
68
+ representing a project or community include using an official project e-mail
69
+ address, posting via an official social media account, or acting as an appointed
70
+ representative at an online or offline event. Representation of a project may be
71
+ further defined and clarified by project maintainers.
72
+
73
+ ### Enforcement
74
+
75
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
76
+ reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
77
+ complaints will be reviewed and investigated and will result in a response that
78
+ is deemed necessary and appropriate to the circumstances. The project team is
79
+ obligated to maintain confidentiality with regard to the reporter of an incident.
80
+ Further details of specific enforcement policies may be posted separately.
81
+
82
+ Project maintainers who do not follow or enforce the Code of Conduct in good
83
+ faith may face temporary or permanent repercussions as determined by other
84
+ members of the project's leadership.
85
+
86
+ ### Attribution
87
+
88
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
89
+ available at [http://contributor-covenant.org/version/1/4][version]
90
+
91
+ [homepage]: http://contributor-covenant.org
92
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dclog (0.2.0)
4
+ dclog (0.3.0)
5
5
  rails (>= 5.0.0)
6
6
 
7
7
  GEM
@@ -73,21 +73,21 @@ GEM
73
73
  diff-lcs (1.4.4)
74
74
  docile (1.4.0)
75
75
  erubi (1.10.0)
76
- globalid (0.4.2)
77
- activesupport (>= 4.2.0)
76
+ globalid (0.5.2)
77
+ activesupport (>= 5.0)
78
78
  i18n (1.8.10)
79
79
  concurrent-ruby (~> 1.0)
80
- loofah (2.10.0)
80
+ loofah (2.12.0)
81
81
  crass (~> 1.0.2)
82
82
  nokogiri (>= 1.5.9)
83
83
  mail (2.7.1)
84
84
  mini_mime (>= 0.1.1)
85
- marcel (1.0.1)
85
+ marcel (1.0.2)
86
86
  method_source (1.0.0)
87
87
  mini_mime (1.1.1)
88
88
  minitest (5.14.4)
89
- nio4r (2.5.7)
90
- nokogiri (1.11.7-x86_64-linux)
89
+ nio4r (2.5.8)
90
+ nokogiri (1.12.5-x86_64-linux)
91
91
  racc (~> 1.4)
92
92
  parallel (1.20.1)
93
93
  parser (3.0.1.1)
@@ -114,7 +114,7 @@ GEM
114
114
  rails-dom-testing (2.0.3)
115
115
  activesupport (>= 4.2.0)
116
116
  nokogiri (>= 1.6)
117
- rails-html-sanitizer (1.3.0)
117
+ rails-html-sanitizer (1.4.2)
118
118
  loofah (~> 2.3)
119
119
  railties (6.1.4.1)
120
120
  actionpack (= 6.1.4.1)
data/README.md CHANGED
@@ -29,17 +29,16 @@ Rails.application.configure do
29
29
  ...
30
30
 
31
31
  logger = ActiveSupport::Logger.new($stdout)
32
- logger.formatter = proc do |severity, datetime, progname, message|
33
- "#{JSON.dump(
34
- severity: severity,
35
- date: datetime.strftime('%Y-%m-%d %H:%M:%S'),
36
- caller: progname,
37
- message: message
38
- )}\n"
39
- end
32
+ logger.formatter = Dclog::LogFormatter.new
40
33
  config.logger = ActiveSupport::TaggedLogging.new(logger)
34
+
41
35
  level = ENV.fetch('LOG_LEVEL', 'info')
42
36
  config.log_level = Rails.env.test? ? :warn : level.underscore.to_sym
37
+
38
+ # add silencers for useless logs (optional)
39
+ # config.logger.formatter.add_silencer { |line| line =~ /\/sidekiq/ }
40
+ # config.logger.formatter.add_silencer { |line| line =~ /\/app_health/ }
41
+
43
42
  config.log_tags = [:request_id]
44
43
 
45
44
  ...
data/dclog.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = 'dclog'
7
7
  spec.version = Dclog::VERSION
8
8
  spec.authors = ['Jairo Junior', 'Matheus Acosta', 'Vinicius Machado']
9
- spec.email = ['jairo.junior@deliverycenter.com', 'matheus.martins@deliverycenter.com',
9
+ spec.email = ['jairo.junior@deliverycenter.com', 'matheusthebr@gmail.com',
10
10
  'vinicius.santana@deliverycenter.com']
11
11
 
12
12
  spec.summary = 'A logger'
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Dclog::Formatter
4
+ LOG_REGEX = /^\[([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\]\s+(.+)$/.freeze
5
+
6
+ def initialize
7
+ @silencers = []
8
+ end
9
+
10
+ def add_silencer(&block)
11
+ @silencers << block
12
+ end
13
+
14
+ def call(severity, timestamp, progname, message)
15
+ return if should_filter?(message)
16
+
17
+ msg_regex = message.match(LOG_REGEX)
18
+ request_id = msg_regex.nil? ? nil : msg_regex[1]
19
+ msg = msg_regex.nil? ? message : msg_regex[2]
20
+
21
+ "#{JSON.dump(
22
+ severity: severity,
23
+ date: timestamp.strftime("%Y-%m-%d %H:%M:%S"),
24
+ caller: progname,
25
+ request_id: request_id,
26
+ message: msg
27
+ )}\n"
28
+ end
29
+
30
+ private
31
+
32
+ def should_filter?(message)
33
+ return false if @silencers.empty?
34
+
35
+ @silencers.each { |silencer| return true if silencer.call(message) }
36
+
37
+ false
38
+ end
39
+ end
data/lib/dclog/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dclog
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/dclog.rb CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  require 'rails'
4
4
  require_relative 'dclog/version'
5
+ require_relative 'dclog/formatter'
5
6
 
6
7
  begin
7
8
  require 'sidekiq'
8
9
  rescue LoadError
9
- Rails.logger.info('The Sidekiq gem is not installed')
10
+ puts 'The Sidekiq gem is not installed'
10
11
  end
11
12
 
12
13
  module Dclog
@@ -29,7 +30,7 @@ module Dclog
29
30
  end
30
31
 
31
32
  def raise_no_method_error!(severity)
32
- raise NoMethodError, "undefined method '#{severity}' for Log:Class"
33
+ raise NoMethodError, "undefined method '#{severity}' for Dclog:Class"
33
34
  end
34
35
 
35
36
  def log_to_stdout(severity, caller, message)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dclog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jairo Junior
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-09-10 00:00:00.000000000 Z
13
+ date: 2021-11-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -72,7 +72,7 @@ description: A gem to format logs to json, and run one commando to log into side
72
72
  and rails
73
73
  email:
74
74
  - jairo.junior@deliverycenter.com
75
- - matheus.martins@deliverycenter.com
75
+ - matheusthebr@gmail.com
76
76
  - vinicius.santana@deliverycenter.com
77
77
  executables: []
78
78
  extensions: []
@@ -82,6 +82,7 @@ files:
82
82
  - ".gitignore"
83
83
  - ".rspec"
84
84
  - ".rubocop.yml"
85
+ - CONTRIBUTING.md
85
86
  - Gemfile
86
87
  - Gemfile.lock
87
88
  - LICENSE.txt
@@ -91,6 +92,7 @@ files:
91
92
  - bin/setup
92
93
  - dclog.gemspec
93
94
  - lib/dclog.rb
95
+ - lib/dclog/formatter.rb
94
96
  - lib/dclog/version.rb
95
97
  homepage: https://github.com/deliverycenter/dclog
96
98
  licenses: