fluent_logger_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a88bc428967e9ee7c2f81f9e747b0cc868f52fe9158587c4c847f1516c43d59
4
+ data.tar.gz: 175d618a1cc6cd67e7c137b02328040e256c8f8e101e6d8786501227792453fe
5
+ SHA512:
6
+ metadata.gz: a1557f1bb328c7525b9c7341898c8cfeebe4646a1b2d0741b09cc7e65ae3e2e1de6654b59d8abd1b50818b9e94c2ddc8c95fd3bb40c9d08daf3d632cdf74f11b
7
+ data.tar.gz: ad952d449c9c9e53e3ac59da6da928cb1a34fd01fa4d34d9a2fce3d4160a48b3cca22fe75517b8b62144ae21a878e962abc915a21a97446bb9bc9919a79d6687
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Rubymine
14
+ /.idea
15
+ .rakeTasks
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
@@ -0,0 +1,16 @@
1
+ ## Unreleased Changes
2
+
3
+ [Full Changelog](https://github.com/Hacker0x01/fluent_logger_rails/compare/master)
4
+
5
+ Bug Fixes:
6
+
7
+ * None
8
+
9
+ Enhancements:
10
+
11
+ * Add a rake task to walk through your table/columns and easily classify and create a migration from it
12
+ * Add a migration generator
13
+ * Module helper to include in migrations to add data classification smart comment
14
+
15
+ Deprecations:
16
+ * None
@@ -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 opensource@hackerone.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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent_logger_rails (0.1.0)
5
+ activesupport (~> 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.4.3)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ coderay (1.1.3)
16
+ concurrent-ruby (1.1.6)
17
+ diff-lcs (1.4.4)
18
+ i18n (1.8.3)
19
+ concurrent-ruby (~> 1.0)
20
+ method_source (1.0.0)
21
+ minitest (5.14.1)
22
+ pry (0.13.1)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
+ rspec (3.9.0)
26
+ rspec-core (~> 3.9.0)
27
+ rspec-expectations (~> 3.9.0)
28
+ rspec-mocks (~> 3.9.0)
29
+ rspec-core (3.9.2)
30
+ rspec-support (~> 3.9.3)
31
+ rspec-expectations (3.9.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-mocks (3.9.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-support (3.9.3)
38
+ thread_safe (0.3.6)
39
+ timecop (0.9.1)
40
+ tzinfo (1.2.7)
41
+ thread_safe (~> 0.1)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ fluent_logger_rails!
48
+ pry
49
+ rspec (~> 3.6)
50
+ timecop
51
+
52
+ BUNDLED WITH
53
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 HackerOne Inc.
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.
File without changes
@@ -0,0 +1,35 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "fluent_logger_rails/version"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'fluent_logger_rails'
6
+ spec.version = FluentLoggerRails::VERSION
7
+ spec.date = '2020-07-14'
8
+ spec.summary = "A wrapper for fluent-logger gem to support tagged logging"
9
+ spec.description = "A simple hello world gem"
10
+ spec.authors = ["HackerOne Open Source", "Ben Willis"]
11
+ spec.email = ["opensource+fluent_logger_rails@hackerone.com", "ben@hackeroen.com"]
12
+ spec.homepage = "https://github.com/Hacker0x01/fluent_logger_rails"
13
+
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.add_dependency('activesupport', '~> 5.0')
18
+
19
+ spec.add_development_dependency 'rspec', '~> 3.6'
20
+ spec.add_development_dependency 'timecop'
21
+ spec.add_development_dependency 'pry'
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = "https://github.com/Hacker0x01/fluent_logger_rails"
25
+ spec.metadata["changelog_uri"] = "https://github.com/Hacker0x01/fluent_logger_rails/blob/master/CHANGELOG.md"
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+ end
@@ -0,0 +1,5 @@
1
+ require 'fluent_logger_rails/logger'
2
+ require 'fluent_logger_rails/tagged_logging'
3
+ require 'fluent_logger_rails/hash_formatter'
4
+ require 'fluent_logger_rails/json_formatter'
5
+ require 'fluent_logger_rails/pretty_json_formatter'
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ class HashFormatter
4
+ def call(severity, timestamp, _progname, msg)
5
+ severity_display = if severity.blank?
6
+ 'ANY'
7
+ elsif severity.is_a? Integer
8
+ ActiveSupport::Logger::SEV_LABEL[severity]
9
+ else
10
+ severity
11
+ end
12
+
13
+ {
14
+ severity: severity_display,
15
+ timestamp: timestamp.in_time_zone.strftime('%Y-%m-%d %H:%M:%S.%3N%z'),
16
+ message: msg.is_a?(String) ? msg.strip : msg,
17
+ }.merge(compact_tags)
18
+ end
19
+
20
+ def tagged(*tags)
21
+ add_tags(*tags)
22
+ yield self
23
+ ensure
24
+ remove_tags(*tags)
25
+ end
26
+
27
+ def add_tags(*tags)
28
+ tags = tags.first if tags.length == 1
29
+
30
+ if tags.is_a? Array
31
+ current_tags[:tags] ||= []
32
+ current_tags[:tags] += tags
33
+ elsif tags.is_a? String
34
+ current_tags[:tags] ||= []
35
+ current_tags[:tags] << tags
36
+ else
37
+ current_tags.merge! tags
38
+ end
39
+ end
40
+
41
+ def remove_tags(*tags)
42
+ tags = tags.first if tags.length == 1
43
+
44
+ if tags.is_a? Array
45
+ current_tags[:tags] ||= []
46
+ tags.each { |tag| current_tags[:tags].delete(tag) }
47
+ elsif tags.is_a? String
48
+ current_tags[:tags] ||= []
49
+ current_tags[:tags].delete(tags)
50
+ else
51
+ tags.each_key { |key| current_tags.delete(key) }
52
+ end
53
+ end
54
+
55
+ def clear_tags!
56
+ current_tags.clear
57
+ end
58
+
59
+ def current_tags
60
+ # We use our object ID here to avoid conflicting with other instances
61
+ thread_key = @thread_key ||= "fluent_logger_rails:#{object_id}"
62
+ Thread.current[thread_key] ||= {}
63
+ end
64
+
65
+ def compact_tags
66
+ current_tags.delete_if { |_k, v| v.blank? }
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class JsonFormatter < HashFormatter
4
+ def call(severity, timestamp, progname, msg)
5
+ super(severity, timestamp, progname, msg).to_json
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ require 'active_support'
3
+
4
+ module FluentLoggerRails
5
+ class Logger < ::ActiveSupport::Logger
6
+ def initialize(logger, path:, level:)
7
+ @level = SEV_LABEL.index(level.to_s.upcase)
8
+ @path = path
9
+ @logger = logger
10
+ after_initialize if respond_to? :after_initialize
11
+ end
12
+
13
+ def add(severity, message = nil, progname = nil)
14
+ return true if severity < @level
15
+
16
+ message = (block_given? ? yield : progname) if message.blank?
17
+ return true if message.blank?
18
+
19
+ message = format_message(severity, Time.now, progname, message)
20
+ message = { message: message } unless message.is_a? Hash
21
+
22
+ @logger.post(@path, message)
23
+ true
24
+ end
25
+
26
+ def close
27
+ @logger.close
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PrettyJsonFormatter < HashFormatter
4
+ def call(severity, timestamp, progname, msg)
5
+ JSON.pretty_generate(super(severity, timestamp, progname, msg))
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FluentLoggerRails
4
+ module TaggedLogging
5
+ def self.new(logger, format: :hash)
6
+ logger.formatter = if format == :hash
7
+ HashFormatter.new
8
+ elsif format == :pretty_json
9
+ PrettyJsonFormatter.new
10
+ elsif format == :json
11
+ JsonFormatter.new
12
+ else
13
+ fail "Unrecognized log format: '#{format}'"
14
+ end
15
+
16
+ logger.extend(self)
17
+ end
18
+
19
+ delegate :add_tags, :remove_tags, :clear_tags!, to: :formatter
20
+
21
+ def tagged(*tags)
22
+ formatter.tagged(*tags) { yield self }
23
+ end
24
+
25
+ def flush
26
+ clear_tags!
27
+ super if defined?(super)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module FluentLoggerRails
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent_logger_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - HackerOne Open Source
8
+ - Ben Willis
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-07-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '5.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '5.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.6'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.6'
42
+ - !ruby/object:Gem::Dependency
43
+ name: timecop
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: A simple hello world gem
71
+ email:
72
+ - opensource+fluent_logger_rails@hackerone.com
73
+ - ben@hackeroen.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - fluent_logger_rails.gemspec
87
+ - lib/fluent_logger_rails.rb
88
+ - lib/fluent_logger_rails/hash_formatter.rb
89
+ - lib/fluent_logger_rails/json_formatter.rb
90
+ - lib/fluent_logger_rails/logger.rb
91
+ - lib/fluent_logger_rails/pretty_json_formatter.rb
92
+ - lib/fluent_logger_rails/tagged_logging.rb
93
+ - lib/fluent_logger_rails/version.rb
94
+ homepage: https://github.com/Hacker0x01/fluent_logger_rails
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ homepage_uri: https://github.com/Hacker0x01/fluent_logger_rails
99
+ source_code_uri: https://github.com/Hacker0x01/fluent_logger_rails
100
+ changelog_uri: https://github.com/Hacker0x01/fluent_logger_rails/blob/master/CHANGELOG.md
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.3.0
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A wrapper for fluent-logger gem to support tagged logging
120
+ test_files: []