logist 0.1.0

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: 89bc1e23d5c8e20fc4ab77eb5c195013da0ae18e
4
+ data.tar.gz: 8c549ad528ec961a5420c4bb0406d543bf015391
5
+ SHA512:
6
+ metadata.gz: 8e03a2c4128740077ffc4b0f10bf72fc10df8b01d2b82b536389db2d0a1f5045249be351b984fb08df2eee3a4a2cd73475104965349379f814332c5c1179a24d
7
+ data.tar.gz: 0cd0002275fe6086b0207e7e712248fb969139cf9d7c0c157855f77039da68348f7f606696fdbae4ab43353fbbc6dee9f99fe965d512b431e755e82dce7c6877
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.10
5
+ - 2.2.9
6
+ - 2.3.6
7
+ - 2.4.3
8
+ before_install: gem install bundler -v 1.15.4
9
+ install: bundle install --jobs=3 --retry=3 --path=vendor/bundle
10
+ cache:
11
+ directories: vendor/bundle
12
+ script: bundle exec rspec spec
@@ -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 h3.poteto@gmail.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 [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,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in logist.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 AkiraFukushima
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,85 @@
1
+ # Logist
2
+ [![Build Status](https://travis-ci.org/h3poteto/logist.svg?branch=travis)](https://travis-ci.org/h3poteto/logist)
3
+
4
+ This gem provides json format for logger in Rails. Logist output json log like this:
5
+
6
+ ```
7
+ $ bundle exec rails s -b 0.0.0.0
8
+ => Booting Puma
9
+ => Rails 5.1.4 application starting in development
10
+ => Run `rails server -h` for more startup options
11
+ Puma starting in single mode...
12
+ * Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot
13
+ * Min threads: 1, max threads: 5
14
+ * Environment: development
15
+ * Listening on tcp://0.0.0.0:3000
16
+ Use Ctrl-C to stop
17
+ {"level":"INFO","timestamp":"2017-12-18T08:55:19+00:00","message":"hoge","environment":"development"}
18
+ {"level":"INFO","timestamp":"2017-12-18T08:55:19+00:00","environment":"development","method":"GET","path":"/api/health_check","format":"html","controller":"Api::HealthCheckController","action":"index","status":200,"duration":1.89,"view":0.81,"db":0.0,"exception":null,"exception_object":null}
19
+ ```
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'logist'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install logist
36
+
37
+ ## Usage
38
+
39
+ You have to use logist logger in your `config/evnrionments/[rails-env].rb`:
40
+
41
+ ```ruby
42
+ Rails.application.configure do
43
+ # ...
44
+ config.logger = Logist::Logger.new(STDOUT)
45
+ end
46
+ ```
47
+
48
+ You can change logger configuration like this:
49
+
50
+ ```ruby
51
+ Rails.application.configure do
52
+ # ...
53
+ config.logger = Logist::Logger.new(STDOUT, datetime_format: "%Y-%m-%dT%H:%M:%S%:z:")
54
+ end
55
+ ```
56
+
57
+ or
58
+
59
+ ```ruby
60
+ Rails.application.configure do
61
+ # ...
62
+ config.logger = Logist::Logger.new(STDOUT)
63
+ config.logger.formatter.datetime_format = "%Y-%m-%dT%H:%M:%S%:z"
64
+ end
65
+ ```
66
+
67
+
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ 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).
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/h3poteto/logist. 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.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
+
83
+ ## Code of Conduct
84
+
85
+ Everyone interacting in the Logist project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/h3poteto/logist/blob/master/CODE_OF_CONDUCT.md).
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 "logist"
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
data/lib/logist.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "logist/version"
2
+ require 'logist/formatter/json'
3
+ require 'logist/logger'
4
+ require 'logger'
5
+ require 'lograge'
6
+
7
+ module Logist
8
+ def self.setup(app)
9
+ raise Logist::LoggerError, "You must configure logger to logist" unless enabled?(app)
10
+ end
11
+
12
+ def self.enabled?(app)
13
+ !app.config.logger.nil? && app.config.logger.class == Logist::Logger
14
+ end
15
+ end
16
+
17
+ class Logist::LoggerError < StandardError; end
18
+
19
+ require 'logist/railtie' if defined?(Rails)
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+ require 'logger'
3
+ require 'rails'
4
+
5
+ module Logist
6
+ module Formatter
7
+ class Json < ::Logger::Formatter
8
+ def call(severity, timestamp, progname, msg)
9
+ begin
10
+ j = ::JSON.parse(msg)
11
+ temp = {level: severity, timestamp: format_datetime(timestamp), environment: ::Rails.env}.merge(j)
12
+ ::JSON.dump(temp) + "\n"
13
+ rescue JSON::ParserError
14
+ "{\"level\":\"#{severity}\",\"timestamp\":\"#{format_datetime(timestamp)}\",\"message\":\"#{msg}\",\"environment\":\"#{::Rails.env}\"}\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module Logist
2
+ class Logger < ::Logger
3
+ def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
4
+ progname: nil, formatter: nil, datetime_format: nil,
5
+ shift_period_suffix: '%Y%m%d')
6
+ # I think that Logist should support other formats in the future.
7
+ # But, as it is now, Logist only support json format.
8
+ # So this line force json format all environments.
9
+ @formatter = Logist::Formatter::Json.new
10
+ @formatter.datetime_format = datetime_format
11
+ super(logdev, shift_age, shift_size, level: level,
12
+ progname: progname, formatter: @formatter, datetime_format: datetime_format,
13
+ shift_period_suffix: shift_period_suffix)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/railtie'
2
+ require 'logist/logger'
3
+
4
+ module Logist
5
+ class Railtie < Rails::Railtie
6
+ config.lograge.formatter = Lograge::Formatters::Json.new
7
+ config.lograge.custom_options = lambda do |event|
8
+ {
9
+ exception: event.payload[:exception], # ["ExceptionClass", "the message"]
10
+ exception_object: event.payload[:exception_object] # the exception instance
11
+ }
12
+ end
13
+
14
+ config.after_initialize do |app|
15
+ Logist.setup(app) if Logist.enabled?(app)
16
+ Lograge.setup(app) if Logist.enabled?(app)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Logist
2
+ VERSION = "0.1.0"
3
+ end
data/logist.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "logist/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logist"
8
+ spec.version = Logist::VERSION
9
+ spec.authors = ["AkiraFukushima"]
10
+ spec.email = ["h3.poteto@gmail.com"]
11
+
12
+ spec.summary = %q{Change log format to json in Rails.}
13
+ spec.description = %q{Change log format to json in Rails.}
14
+ spec.homepage = "https://github.com/h3poteto/logist"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+
37
+ spec.add_runtime_dependency "json", ">= 1.8"
38
+ spec.add_runtime_dependency "railties", ">= 4"
39
+ spec.add_runtime_dependency "lograge", ">= 0.7", "< 1.0"
40
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AkiraFukushima
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-19 00:00:00.000000000 Z
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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: railties
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: lograge
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '1.0'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0.7'
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.0'
103
+ description: Change log format to json in Rails.
104
+ email:
105
+ - h3.poteto@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - ".rspec"
112
+ - ".travis.yml"
113
+ - CODE_OF_CONDUCT.md
114
+ - Gemfile
115
+ - LICENSE.txt
116
+ - README.md
117
+ - Rakefile
118
+ - bin/console
119
+ - bin/setup
120
+ - lib/logist.rb
121
+ - lib/logist/formatter/json.rb
122
+ - lib/logist/logger.rb
123
+ - lib/logist/railtie.rb
124
+ - lib/logist/version.rb
125
+ - logist.gemspec
126
+ homepage: https://github.com/h3poteto/logist
127
+ licenses:
128
+ - MIT
129
+ metadata:
130
+ allowed_push_host: https://rubygems.org
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.6.11
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Change log format to json in Rails.
151
+ test_files: []