nav-logger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f1a39fee5ed7b1569a38d0edf614307e52fc09e
4
+ data.tar.gz: 47404afcb426ecb98252047c7576c00dd55ac4d7
5
+ SHA512:
6
+ metadata.gz: 55b5572ce252b6bcb64956f877690608171e6faa5276be4cdcb457ed5581743d4ac0b13a40c31632b24caa03c0f267264f4007ae74a14549045a1d4f4af19efa
7
+ data.tar.gz: d0d38f9b8651597e906cb6330bc634ecd336c0a042592df1e7b0cf42f9e628afb7ea264e6a5a5fa6c1100c8d1853401492d1582b808fd6a9a90cb4b2ac7726e6
data/.gitignore ADDED
@@ -0,0 +1,54 @@
1
+ # From bundle gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /pkg/
7
+
8
+ # Test files #
9
+ /coverage
10
+ /doc
11
+ /test/reports
12
+ /tmp
13
+
14
+ # Vagrant #
15
+ .vagrant
16
+
17
+ # Compiled source #
18
+ *.com
19
+ *.class
20
+ *.dll
21
+ *.exe
22
+ *.o
23
+ *.so
24
+
25
+ # Packages #
26
+ # it's better to unpack these files and commit the raw source
27
+ # git has its own built in compression methods
28
+ *.7z
29
+ *.dmg
30
+ *.gz
31
+ *.iso
32
+ *.jar
33
+ *.rar
34
+ *.tar
35
+ *.zip
36
+
37
+ # Logs and databases #
38
+ *.log
39
+ *.sqlite
40
+
41
+ # OS generated files #
42
+ .DS_Store
43
+ .DS_Store?
44
+ ._*
45
+ .Spotlight-V100
46
+ .Trashes
47
+ ehthumbs.db
48
+ Thumbs.db
49
+
50
+ *.env
51
+
52
+ # Editor-made files #
53
+ *.swp
54
+ .idea
data/.rubocop.yml ADDED
@@ -0,0 +1,72 @@
1
+ # Common configuration.
2
+ AllCops:
3
+ TargetRubyVersion: 2.0
4
+
5
+ Style/FileName:
6
+ Exclude:
7
+ - 'lib/nav-logger.rb'
8
+
9
+ Style/Documentation:
10
+ # Setting to true requires that all classes have a comment above the
11
+ # class definition.
12
+ Enabled: false
13
+
14
+ Style/IndentationConsistency:
15
+ # The difference between `rails` and `normal` is that the `rails` style
16
+ # prescribes that in classes and modules the `protected` and `private`
17
+ # modifier keywords shall be indented the same as public methods and that
18
+ # protected and private members shall be indented one step more than the
19
+ # modifiers. Other than that, both styles mean that entities on the same
20
+ # logical depth shall have the same indentation.
21
+ EnforcedStyle: rails
22
+ SupportedStyles:
23
+ - normal
24
+ - rails
25
+
26
+ Style/StringLiterals:
27
+ EnforcedStyle: double_quotes
28
+ SupportedStyles:
29
+ - single_quotes
30
+ - double_quotes
31
+ # If true, strings which span multiple lines using \ for continuation must
32
+ # use the same type of quotes on each line.
33
+ ConsistentQuotesInMultiline: false
34
+
35
+ Style/StringLiteralsInInterpolation:
36
+ EnforcedStyle: double_quotes
37
+ SupportedStyles:
38
+ - single_quotes
39
+ - double_quotes
40
+
41
+ Metrics/AbcSize:
42
+ # The ABC size is a calculated magnitude, so this number can be an Integer or
43
+ # a Float.
44
+ Max: 35
45
+
46
+ Metrics/BlockLength:
47
+ CountComments: false # count full line comments?
48
+ Max: 30
49
+ Exclude:
50
+ - 'Rakefile'
51
+ - '**/*.rake'
52
+ - 'spec/**/*.rb'
53
+ - 'app/controllers/**.*'
54
+
55
+ # Avoid complex methods.
56
+ Metrics/CyclomaticComplexity:
57
+ Max: 10
58
+
59
+ Metrics/ClassLength:
60
+ CountComments: false # count full line comments?
61
+ Max: 150
62
+
63
+ Metrics/ModuleLength:
64
+ CountComments: false # count full line comments?
65
+ Max: 150
66
+
67
+ Metrics/MethodLength:
68
+ CountComments: false # count full line comments?
69
+ Max: 25
70
+
71
+ Metrics/PerceivedComplexity:
72
+ Max: 12
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at johnnyt@nav.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nav-logger.gemspec
4
+ gemspec
5
+
6
+ # Development and test dependencies here
7
+ gem "bundler"
8
+ gem "guard"
9
+ gem "guard-minitest"
10
+ gem "guard-bundler"
11
+ gem "guard-rubocop"
12
+ gem "minitest", "~> 5.0"
13
+ gem "pry-nav"
14
+ gem "rake", "~> 10.0"
15
+ gem "rubocop", require: false
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ guard :bundler do
2
+ require "guard/bundler"
3
+ require "guard/bundler/verify"
4
+ helper = Guard::Bundler::Verify.new
5
+
6
+ files = ["Gemfile"]
7
+ files += Dir["*.gemspec"] if files.any? { |f| helper.uses_gemspec?(f) }
8
+
9
+ # Assume files are symlinked from somewhere
10
+ files.each { |file| watch(helper.real_path(file)) }
11
+ end
12
+
13
+ guard :rubocop do
14
+ watch(/^.+\.rb$/)
15
+ watch(/^(Gem|Guard|Rake)file$/)
16
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
17
+ end
18
+
19
+ guard :minitest do
20
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
21
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
22
+ watch(%r{^test/helper\.rb$}) { "test" }
23
+ watch(%r{^config/*\.rb$})
24
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 JohnnyT
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,39 @@
1
+ # Nav::Logger
2
+
3
+ Nav's logger
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "nav-logger"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nav-logger
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/creditera/nav-logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "guard/rake_task"
3
+ require "rake/testtask"
4
+
5
+ Guard::RakeTask.new
6
+
7
+ Rake::TestTask.new :test do |t|
8
+ t.libs << "test"
9
+ # t.warning = false
10
+ t.test_files = FileList["test/**/test_*.rb"]
11
+ end
12
+
13
+ desc "Run the tests"
14
+ task default: :test
data/bin/_guard-core ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application '_guard-core' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("guard", "_guard-core")
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nav/logger"
5
+
6
+ require "pry-nav"
7
+ Pry.start
data/bin/guard ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'guard' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("guard", "guard")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/nav-logger.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative "nav/logger"
data/lib/nav/logger.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "fluent-logger"
2
+ require "request_store"
3
+ require "logger"
4
+ require "socket"
5
+
6
+ require "nav/logger/base_logger"
7
+ require "nav/logger/console_logger"
8
+ require "nav/logger/default_logger"
9
+ require "nav/logger/test_logger"
10
+ require "nav/logger/version"
11
+
12
+ module Nav
13
+ module_function
14
+
15
+ def logger
16
+ @logger ||= create_logger
17
+ end
18
+
19
+ def logger=(new_logger)
20
+ @logger = new_logger
21
+ end
22
+
23
+ def create_logger
24
+ environment = ENV["RACK_ENV"] || ENV["APP_ENV"] || "development"
25
+
26
+ case environment
27
+ when "development"
28
+ Logger::ConsoleLogger.new
29
+ when "test"
30
+ Logger::TestLogger.new
31
+ else
32
+ Logger::DefaultLogger.new
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,86 @@
1
+ module Nav
2
+ module Logger
3
+ class BaseLogger
4
+ attr_reader :fluent_logger
5
+
6
+ def level
7
+ @level ||= ::Logger::DEBUG
8
+ end
9
+
10
+ def level_name(lookup = level)
11
+ ::Logger::SEV_LABEL[lookup]
12
+ end
13
+
14
+ def level_symbol
15
+ level_name.downcase.to_sym
16
+ end
17
+
18
+ def level=(new_level)
19
+ if new_level.is_a? Integer
20
+ @level = new_level
21
+ else
22
+ lookup = new_level.to_s.upcase
23
+ @level = ::Logger::SEV_LABEL.index lookup
24
+ end
25
+ end
26
+
27
+ def debug(message, hash = {})
28
+ add ::Logger::DEBUG, message, hash
29
+ end
30
+
31
+ def info(message, hash = {})
32
+ add ::Logger::INFO, message, hash
33
+ end
34
+
35
+ def warn(message, hash = {})
36
+ add ::Logger::WARN, message, hash
37
+ end
38
+
39
+ def error(message, hash = {})
40
+ add ::Logger::ERROR, message, hash
41
+ end
42
+
43
+ def fatal(message, hash = {})
44
+ add ::Logger::FATAL, message, hash
45
+ end
46
+
47
+ private
48
+
49
+ def add(severity, message, hash)
50
+ severity = severity.nil? ? ::Logger::UNKNOWN : severity.to_i
51
+ return true if severity < level
52
+
53
+ severity_name = level_name severity
54
+ log_hash = generate_log_hash severity_name, message, hash
55
+ @fluent_logger.post tag(severity_name), log_hash
56
+ end
57
+
58
+ def app_tag
59
+ return @app_tag if defined? @app_tag
60
+ @app_tag = defined?(::APP_PREFIX) ? ::APP_PREFIX.downcase : nil
61
+ end
62
+
63
+ def environment
64
+ @environment ||= ENV["RACK_ENV"] || ENV["APP_ENV"] || "development"
65
+ end
66
+
67
+ def hostname
68
+ @hostname ||= Socket.gethostname
69
+ end
70
+
71
+ def generate_log_hash(severity, message, input)
72
+ hash = input.merge RequestStore.store
73
+ hash.merge! message: message,
74
+ level: severity,
75
+ ts: Time.now.to_f,
76
+ environment: environment,
77
+ hostname: hostname
78
+ hash
79
+ end
80
+
81
+ def tag(severity)
82
+ [app_tag, severity.downcase].compact.join "."
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,9 @@
1
+ module Nav
2
+ module Logger
3
+ class ConsoleLogger < BaseLogger
4
+ def initialize
5
+ @fluent_logger = Fluent::Logger::ConsoleLogger.open STDOUT
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Nav
2
+ module Logger
3
+ class DefaultLogger < BaseLogger
4
+ def initialize
5
+ @fluent_logger = Fluent::Logger::FluentLogger.new nil
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Nav
2
+ module Logger
3
+ class TestLogger < BaseLogger
4
+ def initialize
5
+ @fluent_logger = Fluent::Logger::TestLogger.new
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Nav
2
+ module Logger
3
+ VERSION = "0.0.1".freeze
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path "../lib", __FILE__
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
4
+ require "nav/logger/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nav-logger"
8
+ spec.version = Nav::Logger::VERSION
9
+ spec.authors = ["JohnnyT"]
10
+ spec.email = ["ubergeek3141@gmail.com"]
11
+
12
+ spec.summary = "Nav's logger"
13
+ spec.homepage = "https://github.com/creditera/nav-logger"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`
17
+ .split("\x0")
18
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "fluent-logger", "~> 0.6.1"
24
+ spec.add_dependency "request_store"
25
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nav-logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - JohnnyT
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluent-logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: request_store
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - ubergeek3141@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rubocop.yml"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - Guardfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/_guard-core
58
+ - bin/console
59
+ - bin/guard
60
+ - bin/setup
61
+ - lib/nav-logger.rb
62
+ - lib/nav/logger.rb
63
+ - lib/nav/logger/base_logger.rb
64
+ - lib/nav/logger/console_logger.rb
65
+ - lib/nav/logger/default_logger.rb
66
+ - lib/nav/logger/test_logger.rb
67
+ - lib/nav/logger/version.rb
68
+ - nav-logger.gemspec
69
+ homepage: https://github.com/creditera/nav-logger
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.5.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Nav's logger
93
+ test_files: []
94
+ has_rdoc: