xyeger 0.1.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: 3e103637d758bf273e499346bfbba7ae255126ac
4
+ data.tar.gz: e09123e3824b1c8613092b91bdf86f5e822111c7
5
+ SHA512:
6
+ metadata.gz: 8b728fc45afff886a7d0d498e8aa1a85febc4a5d609cd0451cfbb34b2b2d440c613e70d2b073c9aab8b6729fb28b1bd3447a29401220f1968ebb6acb3dfcab68
7
+ data.tar.gz: 9a254f25e04fa2e463e004d19806f0e38c7660881368669b2f5ba7eab444dc1bb35903e0c5b891ebdb1c70d556d5cd131198a7d7736c71f5d1a13a4637965b94
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .rspec
2
+ .travis.yml
@@ -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 vsevolod@cryptopay.me. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xyeger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Avramov Vsevolod
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,110 @@
1
+ # Xyeger
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'xyeger'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install xyeger
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ Add environments:
24
+ ```bash
25
+ XYEGER_HOSTNAME='LoggerApplication' #f.e.: rails, sidekiq, sneakers
26
+ ```
27
+
28
+ Add into environment file:
29
+ ```ruby
30
+ #config/environments/production.rb
31
+ Rails.application.configure do
32
+ config.xyeger.enabled = true
33
+ end
34
+ ```
35
+
36
+ ## Output results
37
+
38
+ ### Http request
39
+ ```bash
40
+ curl localhost:3000 -G -d a=3
41
+ ```
42
+ ```json
43
+ {
44
+ "logger": "puma: cluster worker 1: 29117 [cryptopay]",
45
+ "pid": 29141,
46
+ "app": "Cryptopay",
47
+ "env": "development",
48
+ "level": "INFO",
49
+ "time": "2017-06-29T15:42:14.761+03:00",
50
+ "caller": null,
51
+ "msg": "Lograge message",
52
+ "context":
53
+ {"method": "GET",
54
+ "path": "/",
55
+ "format": "*/*",
56
+ "controller": "PagesController",
57
+ "action": "index",
58
+ "status": 200,
59
+ "duration": 1852.79,
60
+ "view": 703.55,
61
+ "db": 29.07,
62
+ "params": {"a": "3"}}
63
+ }
64
+ ```
65
+
66
+ ### Raise an error
67
+ ```json
68
+ {
69
+ "logger":"puma",
70
+ "pid":24886,
71
+ "app":"Cryptopay",
72
+ "env":"development",
73
+ "level":"ERROR",
74
+ "time":"2017-06-29T15:17:07.736+03:00",
75
+ "caller":"/home/vsevolod/work/cryptopay/cryptopay/app/services/ticker_service.rb:159",
76
+ "msg": "StandardError",
77
+ "context":
78
+ {
79
+ "class": "TickerService::TickerNotFound",
80
+ "error": "Active ticker not found EUR/USD"
81
+ }
82
+ }
83
+ ```
84
+
85
+ ### Manual log usage
86
+ ```ruby
87
+ Rails.logger.info('Logger message', { content: '1', params: 'b' })
88
+ ```
89
+ ```json
90
+ {
91
+ "logger":"bin/rails",
92
+ "pid":22796,
93
+ "app":"Cryptopay",
94
+ "env":"development",
95
+ "level":"INFO",
96
+ "time":"2017-06-30T13:45:22.070+03:00",
97
+ "caller":null,
98
+ "message":"Logger message",
99
+ "context":
100
+ {
101
+ "content":"1",
102
+ "params":"b"
103
+ }
104
+ }
105
+
106
+ ```
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
110
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "xyeger"
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,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
@@ -0,0 +1,38 @@
1
+ module Xyeger
2
+ module Formatters
3
+ class Json < ActiveSupport::Logger::SimpleFormatter
4
+ def call(severity, timestamp, context, message)
5
+ message, context = prepare(message, context)
6
+
7
+ {
8
+ logger: ENV.fetch('XYEGER_HOSTNAME', $0),
9
+ pid: $$,
10
+ app: Rails.application.class.parent_name,
11
+ env: Rails.env,
12
+ level: severity,
13
+ time: timestamp,
14
+ caller: caller_message(caller_locations),
15
+ message: message,
16
+ context: context
17
+ }.to_json + "\n"
18
+ end
19
+
20
+ def caller_message(callers)
21
+ if location = callers.find{|x| x.path.include?(Rails.root.to_s)}
22
+ "#{location.path}:#{location.lineno}"
23
+ end
24
+ end
25
+
26
+ def prepare(message, context)
27
+ case message
28
+ when LogrageRaw
29
+ ['Lograge', message.data]
30
+ when ::StandardError
31
+ ['StandardError', { class: message.class.name, error: message.to_s }]
32
+ else
33
+ [message.to_s, context]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ module Xyeger
2
+ module Formatters
3
+ class LogrageRaw < ActiveSupport::OrderedOptions
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Xyeger
2
+ module Formatters
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Json
6
+ autoload :LogrageRaw
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module Xyeger
2
+ class Logger < ActiveSupport::Logger
3
+ def initialize(*args)
4
+ super
5
+ @formatter = Formatters::Json.new
6
+ end
7
+
8
+ Logger::Severity.constants.each do |severity|
9
+ define_method "#{severity.downcase}" do |message, context={}|
10
+ add(Logger::Severity.const_get(severity), message, context)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/railtie'
2
+ require 'action_view/log_subscriber'
3
+ require 'action_controller/log_subscriber'
4
+
5
+ module Xyeger
6
+ class Raitie < Rails::Railtie
7
+ config.xyeger = ActiveSupport::OrderedOptions.new
8
+ config.xyeger.enabled = false
9
+ config.xyeger.output = STDOUT
10
+
11
+ config.after_initialize do |app|
12
+ Xyeger.setup(app) if app.config.xyeger.enabled
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Xyeger
2
+ VERSION = '0.1.1'.freeze
3
+ end
data/lib/xyeger.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'active_support/logger'
2
+ require 'active_support/dependencies/autoload'
3
+ require 'active_support/ordered_options'
4
+ require "xyeger/version"
5
+
6
+ module Xyeger
7
+ module_function
8
+
9
+ extend ActiveSupport::Autoload
10
+
11
+ autoload :Logger
12
+ autoload :Formatters
13
+
14
+ def setup(app)
15
+ setup_lograge(app)
16
+
17
+ app.config.logger = Logger.new(app.config.xyeger.output)
18
+ Rails.logger = app.config.logger
19
+ end
20
+
21
+ def setup_lograge(app)
22
+ app.config.lograge.formatter = -> (data) { Formatters::LogrageRaw.new(data: data) }
23
+ app.config.lograge.custom_options = lambda do |event|
24
+ { params: event.payload[:params]&.except('controller', 'action', 'format', 'id') }
25
+ end
26
+
27
+ Lograge.setup(app)
28
+ end
29
+ end
30
+
31
+ require 'xyeger/railtie' if defined?(Rails)
data/xyeger.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'xyeger/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "xyeger"
9
+ spec.version = Xyeger::VERSION
10
+ spec.authors = ["Avramov Vsevolod"]
11
+ spec.email = ["vsevolod@cryptopay.me"]
12
+
13
+ spec.summary = 'Uniq logger for project'
14
+ spec.description = 'Uniq logger for project'
15
+ spec.homepage = ''
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_dependency 'lograge', '>= 0.4'
35
+ spec.add_runtime_dependency 'activesupport', '>= 4'
36
+ spec.add_runtime_dependency 'actionpack', '>= 4'
37
+ spec.add_runtime_dependency 'railties', '>= 4'
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.14"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xyeger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Avramov Vsevolod
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lograge
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Uniq logger for project
112
+ email:
113
+ - vsevolod@cryptopay.me
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - CODE_OF_CONDUCT.md
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/xyeger.rb
127
+ - lib/xyeger/formatters.rb
128
+ - lib/xyeger/formatters/json.rb
129
+ - lib/xyeger/formatters/lograge_raw.rb
130
+ - lib/xyeger/logger.rb
131
+ - lib/xyeger/railtie.rb
132
+ - lib/xyeger/version.rb
133
+ - xyeger.gemspec
134
+ homepage: ''
135
+ licenses:
136
+ - MIT
137
+ metadata:
138
+ allowed_push_host: https://rubygems.org
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.10
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Uniq logger for project
159
+ test_files: []