rack-access_log 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: 56c846d27381681670964c37eb0f18f2b48f5e6a
4
+ data.tar.gz: b995a96573a52d908fc9f833dc0644d7683ba295
5
+ SHA512:
6
+ metadata.gz: eab15a1e29481ecaf3d812e330cc7f29acff22bac4b85eb84713596a484ddf646966acea3fde36798c0c5120ce299d315bb8a8655fc90d6a287ec19bc6a78c5f
7
+ data.tar.gz: 8f179a2a3d1518a3d683193f031bdf3c8ac6095ec57b426082f1cf65cd4f0fc89f698c324378e88d96a4356e0ce4a80fe89737f46e07e0043592cca21a9e9a11
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,33 @@
1
+ language: ruby
2
+ script: rspec spec -f d
3
+
4
+ install:
5
+ - gem update bundler
6
+ - bundle install
7
+
8
+ rvm:
9
+ - 1.9
10
+ - 2.0.0
11
+ - 2.1.1
12
+ - 2.1.2
13
+ - 2.2.2
14
+ - 2.3.1
15
+ - 2.4.1
16
+ - jruby-19mode
17
+
18
+ - ruby-head
19
+ - jruby-head
20
+
21
+ matrix:
22
+ allow_failures:
23
+ - rvm: ruby-head
24
+ - rvm: jruby-head
25
+
26
+ env:
27
+ global:
28
+ - VERBOSE=true
29
+ - TIMEOUT=1
30
+
31
+ branches:
32
+ only:
33
+ - master
@@ -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 adamluzsi@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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-access_log.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Rack::AccessLog
2
+
3
+ This is a middleware for ruby / rack based webservice access logging.
4
+ The implementation doesn't depend on any webframework or monkey patch.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rack-access_log'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rack-access_log
21
+
22
+ ## Usage
23
+
24
+ #### First we need a logger that can accept and handle hash messages.
25
+
26
+ You can use the ruby build in with "custom" formatter.
27
+
28
+ ```ruby
29
+ require 'json'
30
+ require 'logger'
31
+
32
+ json_logger = Logger.new(STDOUT)
33
+ json_logger.formatter = proc do |severity, datetime, progname, msg|
34
+ JSON.dump(msg) + "\n"
35
+ end
36
+ ```
37
+
38
+ Or you can use logger implementations such as [TwP/logging](https://github.com/TwP/logging) gem
39
+
40
+ ```ruby
41
+ require 'logging'
42
+
43
+ json_logger = Logging.logger["AccessLog"]
44
+ appender = Logging.appenders.stdout(:layout => Logging.layouts.json)
45
+ json_logger.add_appenders(appender)
46
+ ```
47
+
48
+ #### Than use it in our middleware stack
49
+ ##### config.ru
50
+
51
+ ```ruby
52
+ require 'rack/access_log'
53
+ use Rack::AccessLog, json_logger
54
+
55
+ require 'rack/response'
56
+ run proc{|env| Rack::Response.new.finish }
57
+ ```
58
+
59
+ That's all Folks!
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rack-access_log. 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.
64
+
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 "rack/access_log"
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,5 @@
1
+ module Rack
2
+ class AccessLog
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'rack/access_log/version'
2
+ require 'rack'
3
+ require 'benchmark'
4
+
5
+ module Rack
6
+ class AccessLog
7
+ def initialize(app, logger, config = {})
8
+ @app = app
9
+ @logger = logger
10
+ configure!(config)
11
+ end
12
+
13
+ def call(env)
14
+ status, header, body_lines, realtime = next_middleware_call_with_benchmarking(env)
15
+ @logger.info(create_log_message(env, status, realtime)) if tracked?(env)
16
+ [status, header, body_lines]
17
+ end
18
+
19
+ private
20
+
21
+ def tracked?(env)
22
+ !@exclude_paths.include?(env[Rack::PATH_INFO])
23
+ end
24
+
25
+ def create_log_message(env, status, realtime)
26
+ {
27
+ execution_time_sec: realtime,
28
+ remote_ip: remote_ip_by(env),
29
+ request_method: env[Rack::REQUEST_METHOD],
30
+ request_path: env[Rack::PATH_INFO],
31
+ query_string: env[Rack::QUERY_STRING],
32
+ response_status_code: status.to_i
33
+ }
34
+ end
35
+
36
+ def remote_ip_by(env)
37
+ env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_ADDR'] || '-'
38
+ end
39
+
40
+ def next_middleware_call_with_benchmarking(env)
41
+ status = nil
42
+ header = nil
43
+ body_lines = nil
44
+ realtime = Benchmark.realtime do
45
+ status, header, body_lines = @app.call(env)
46
+ end
47
+ [status, header, body_lines, realtime]
48
+ end
49
+
50
+ def configure!(config)
51
+ @exclude_paths = [config.delete(:exclude_path)].flatten.compact.freeze
52
+ check_for_unrequired_options(config)
53
+ end
54
+
55
+ def check_for_unrequired_options(config)
56
+ invalid_config_options = config.keys
57
+ raise("invalid config: #{invalid_config_options.join(', ')}") unless invalid_config_options.empty?
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rack/access_log/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rack-access_log'
9
+ spec.version = Rack::AccessLog::VERSION
10
+ spec.authors = ['Adam Luzsi']
11
+ spec.email = ['smart-insight-dev@emarsys.com']
12
+
13
+ spec.summary = 'This is a super simple access log middleware that can be used without any framework dependency'
14
+ spec.description = 'This is a super simple access log middleware that can be used without any framework dependency'
15
+ spec.homepage = 'https://github.com/emartech/rack-access_log'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'rack'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.14'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-access_log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Luzsi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: This is a super simple access log middleware that can be used without
70
+ any framework dependency
71
+ email:
72
+ - smart-insight-dev@emarsys.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/rack/access_log.rb
87
+ - lib/rack/access_log/version.rb
88
+ - rack-access_log.gemspec
89
+ homepage: https://github.com/emartech/rack-access_log
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: This is a super simple access log middleware that can be used without any
112
+ framework dependency
113
+ test_files: []