ramolog 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +3 -0
- data/LICENSE +24 -0
- data/README.md +63 -0
- data/Rakefile +2 -0
- data/lib/ramolog.rb +2 -0
- data/lib/ramolog/main.rb +48 -0
- data/lib/ramolog/version.rb +3 -0
- data/ramolog.gemspec +28 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7d58e04715c465b202863f11daab743ed2b2378
|
4
|
+
data.tar.gz: 91430b8e61c182b6fcdbabbecde42b19e21b5201
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02ea2f20554cef5a49b11f4e0bbf78b3942f3c78514367b98bf98c737f063e335e5e1b09d0a5780a3322390c1fa740ecfe544f5a59c20910f4f901d729b580f2
|
7
|
+
data.tar.gz: 26c7e34a2daf6929dd68f965d24e396cd3025f620e3a7b7064a11314b05f61f155646fc1019c7c15bbf328604bd8ef612324580ba2625c0105444a9210a1d785
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2015, Takashi Toyoshima
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
20
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
21
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
22
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
23
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Ramolog
|
2
|
+
|
3
|
+
MongoDB backed Rack's CommonLogger replacement.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ramolog'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ramolog
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
*app.rb*
|
24
|
+
```node
|
25
|
+
require 'sinatra'
|
26
|
+
|
27
|
+
configure do
|
28
|
+
use Ramolog::Logger, ENV['MONGOLAB_URI'], 'log'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Log format example
|
33
|
+
```json
|
34
|
+
{
|
35
|
+
"_id": {
|
36
|
+
"$oid": "567b9cc2295d3b000300001d"
|
37
|
+
},
|
38
|
+
"format": 1,
|
39
|
+
"date": "2015-12-24T07:20:34+00:00",
|
40
|
+
"referrer": "-",
|
41
|
+
"request": {
|
42
|
+
"method": "GET",
|
43
|
+
"host": "www.toyoshima-house.net",
|
44
|
+
"url": "http://www.toyoshima-house.net/index.html",
|
45
|
+
"protocol": "HTTP/1.1",
|
46
|
+
"acceptLanguage": "zh-cn,zh-tw"
|
47
|
+
},
|
48
|
+
"response": {
|
49
|
+
"status": 200,
|
50
|
+
"contentLength": 105,
|
51
|
+
"responseTime": 0.408114
|
52
|
+
},
|
53
|
+
"remote": {
|
54
|
+
"addr": "*.*.*.*",
|
55
|
+
"user": "-",
|
56
|
+
"userAgent": "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
## For other languages
|
62
|
+
|
63
|
+
- Express / Node.js: [momolog](https://github.com/toyoshim/momolog)
|
data/Rakefile
ADDED
data/lib/ramolog.rb
ADDED
data/lib/ramolog/main.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Ramolog
|
5
|
+
class Logger
|
6
|
+
def initialize(app, uri, collection)
|
7
|
+
@app = app
|
8
|
+
@db = Mongo::Client.new(uri)
|
9
|
+
@collection = @db[collection]
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
begin_at = Time.now
|
14
|
+
status, header, body = @app.call(env)
|
15
|
+
end_at = Time.now
|
16
|
+
|
17
|
+
# Retrieve the original remote host if running behind a front end.
|
18
|
+
remote_addr = env['REMOTE_ADDR'] or '-'
|
19
|
+
if forwarded = env['HTTP_X_FORWARDED_FOR'] then
|
20
|
+
remote_addr = forwarded.split(',')[-1]
|
21
|
+
end
|
22
|
+
|
23
|
+
@collection.insert_one({
|
24
|
+
format: 1,
|
25
|
+
date: begin_at.iso8601,
|
26
|
+
referrer: (env['HTTP_REFFERER'] or '-'),
|
27
|
+
request: {
|
28
|
+
method: env['REQUEST_METHOD'],
|
29
|
+
host: (env['HTTP_HOST'] or '-'),
|
30
|
+
url: env['REQUEST_URI'],
|
31
|
+
protocol: env['HTTP_VERSION'],
|
32
|
+
acceptLanguage: (env['HTTP_ACCEPT_LANGUAGE'] or '-')
|
33
|
+
},
|
34
|
+
response: {
|
35
|
+
status: status,
|
36
|
+
contentLength: (header['Content-Length'] or '-1').to_i,
|
37
|
+
responseTime: (end_at - begin_at) * 1000 # msec
|
38
|
+
},
|
39
|
+
remote: {
|
40
|
+
addr: remote_addr,
|
41
|
+
user: (env['REMOTE_USER'] or '-'),
|
42
|
+
userAgent: (env['HTTP_USER_AGENT'] or '-')
|
43
|
+
}
|
44
|
+
})
|
45
|
+
[status, header, body]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/ramolog.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ramolog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ramolog"
|
8
|
+
spec.version = Ramolog::VERSION
|
9
|
+
spec.authors = ["Takashi Toyoshima"]
|
10
|
+
spec.email = ["toyoshim@gmail.com"]
|
11
|
+
spec.summary = "MongoDB backed Rack's CommonLogger replacement."
|
12
|
+
spec.description = <<-EOD
|
13
|
+
Momolog is a simple CommonLogger replacement for Rack.
|
14
|
+
This module allows you to use MongoDB to store access logs.
|
15
|
+
EOD
|
16
|
+
spec.homepage = "https://github.com/toyoshim/ramolog"
|
17
|
+
spec.license = "BSD"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "mongo", "~> 2.1"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ramolog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi Toyoshima
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mongo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
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.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
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
|
+
description: |
|
56
|
+
Momolog is a simple CommonLogger replacement for Rack.
|
57
|
+
This module allows you to use MongoDB to store access logs.
|
58
|
+
email:
|
59
|
+
- toyoshim@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/ramolog.rb
|
70
|
+
- lib/ramolog/main.rb
|
71
|
+
- lib/ramolog/version.rb
|
72
|
+
- ramolog.gemspec
|
73
|
+
homepage: https://github.com/toyoshim/ramolog
|
74
|
+
licenses:
|
75
|
+
- BSD
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: MongoDB backed Rack's CommonLogger replacement.
|
97
|
+
test_files: []
|