mongo_request_logger 0.6.0 → 0.7.0
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile +2 -2
- data/README.md +6 -4
- data/gemfiles/rails4.2.gemfile +2 -3
- data/gemfiles/sinatra1.4.gemfile +2 -3
- data/lib/mongo_request_logger.rb +2 -3
- data/lib/mongo_request_logger/version.rb +1 -1
- data/spec/dummy/config/mongoid.yml +1 -1
- metadata +2 -13
- data/lib/mongo_request_logger/mongoid_config.rb +0 -95
- data/spec/testapp/app.rb +0 -14
- data/spec/testapp/config.ru +0 -21
- data/spec/testapp/config/logger.yml +0 -6
- data/spec/testapp/log/.gitignore +0 -1
- data/spec/testapp/log/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d80368aaa66825e64d487fda42dfc49971405c93
|
4
|
+
data.tar.gz: ce9c93717c84a69b8146e5a453f70532a59ce85b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca4cd287d1f02f26ceb3f643915316e4c8de84968122c193fca25274330f4059b5f51e8e6a8838ee9df199fd26b1d1fc89d6590584f789eb7b7dfe69573daa92
|
7
|
+
data.tar.gz: 06addefe92b727a9594303885a80565b3bdc116bf3869e0cc13fce10469233ac371a2674a19f3b2106a08cd339439e146177ed21b2713294d5d7d6fc3e510081
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
## 0.7.0
|
2
|
+
|
3
|
+
*Backwards incompatible!*
|
4
|
+
|
5
|
+
* Deprecate Mongoid 4 support in favour of Mongoid 5
|
6
|
+
|
1
7
|
## 0.6.0
|
2
8
|
|
3
9
|
*Backwards incompatible!*
|
4
10
|
|
5
|
-
* Replace Moped with the official Mongo Ruby Driver, while retaining support for the
|
11
|
+
* Replace Moped with the official Mongo Ruby Driver, while retaining support for the Mongoid 4 configuration file.
|
6
12
|
|
7
13
|
## 0.5.0
|
8
14
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Log requests in a structured format to MongoDB.
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'mongoid', '~>
|
9
|
+
gem 'mongoid', '~> 5.1'
|
10
10
|
gem 'mongo_request_logger'
|
11
11
|
|
12
12
|
## Usage with Rails 4
|
@@ -17,7 +17,7 @@ Add a `logger` session to your Mongoid config, `config/mongoid.yml`. An addition
|
|
17
17
|
Example:
|
18
18
|
|
19
19
|
development:
|
20
|
-
|
20
|
+
clients:
|
21
21
|
logger:
|
22
22
|
database: your_log_db
|
23
23
|
hosts:
|
@@ -25,8 +25,10 @@ Example:
|
|
25
25
|
- host2:27017
|
26
26
|
- host3:27017
|
27
27
|
options:
|
28
|
-
|
29
|
-
|
28
|
+
write:
|
29
|
+
w: 0
|
30
|
+
read:
|
31
|
+
mode: :secondary
|
30
32
|
capsize: 1000 # MB
|
31
33
|
|
32
34
|
Routes for log viewer
|
data/gemfiles/rails4.2.gemfile
CHANGED
data/gemfiles/sinatra1.4.gemfile
CHANGED
data/lib/mongo_request_logger.rb
CHANGED
@@ -12,7 +12,6 @@ require 'mongoid'
|
|
12
12
|
|
13
13
|
require 'mongo'
|
14
14
|
require_relative './mongo_request_logger/adapters/mongo.rb'
|
15
|
-
require_relative './mongo_request_logger/mongoid_config.rb'
|
16
15
|
|
17
16
|
|
18
17
|
module MongoRequestLogger
|
@@ -27,9 +26,9 @@ module MongoRequestLogger
|
|
27
26
|
|
28
27
|
environment = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
29
28
|
|
30
|
-
session =
|
29
|
+
session = Mongoid.client(:logger)
|
31
30
|
if session
|
32
|
-
log_config =
|
31
|
+
log_config = Mongoid.clients[:logger][:options].with_indifferent_access
|
33
32
|
|
34
33
|
fallback_log = options[:fallback_log] || log_config['fallback_log'] || "log/#{environment}.log"
|
35
34
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_request_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Embark Mobile
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -384,7 +384,6 @@ files:
|
|
384
384
|
- lib/mongo_request_logger/logged_job.rb
|
385
385
|
- lib/mongo_request_logger/logger.rb
|
386
386
|
- lib/mongo_request_logger/logger_extensions.rb
|
387
|
-
- lib/mongo_request_logger/mongoid_config.rb
|
388
387
|
- lib/mongo_request_logger/rack.rb
|
389
388
|
- lib/mongo_request_logger/railtie.rb
|
390
389
|
- lib/mongo_request_logger/search_terms.rb
|
@@ -399,11 +398,6 @@ files:
|
|
399
398
|
- spec/rails_spec.rb
|
400
399
|
- spec/shared_examples.rb
|
401
400
|
- spec/spec_helper.rb
|
402
|
-
- spec/testapp/app.rb
|
403
|
-
- spec/testapp/config.ru
|
404
|
-
- spec/testapp/config/logger.yml
|
405
|
-
- spec/testapp/log/.gitignore
|
406
|
-
- spec/testapp/log/.gitkeep
|
407
401
|
- views/index.erb
|
408
402
|
homepage: ''
|
409
403
|
licenses: []
|
@@ -437,8 +431,3 @@ test_files:
|
|
437
431
|
- spec/rails_spec.rb
|
438
432
|
- spec/shared_examples.rb
|
439
433
|
- spec/spec_helper.rb
|
440
|
-
- spec/testapp/app.rb
|
441
|
-
- spec/testapp/config.ru
|
442
|
-
- spec/testapp/config/logger.yml
|
443
|
-
- spec/testapp/log/.gitignore
|
444
|
-
- spec/testapp/log/.gitkeep
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module MongoRequestLogger
|
2
|
-
# Directly parse the mongoig.yml config and present accessors similar to Mongoid 5.
|
3
|
-
# TODO: to be replaced by the Mongoid 5 default behaviour
|
4
|
-
module MongoidConfig
|
5
|
-
def self.clients
|
6
|
-
@clients ||= ClientMap.new
|
7
|
-
end
|
8
|
-
|
9
|
-
class ClientMap
|
10
|
-
attr_reader :config
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@clients = HashWithIndifferentAccess.new
|
14
|
-
config_file = Rails.root.join("config", "mongoid.yml")
|
15
|
-
@config = Environment.load_yaml(config_file).with_indifferent_access
|
16
|
-
@config = @config[:sessions]
|
17
|
-
@config = @config.with_indifferent_access
|
18
|
-
end
|
19
|
-
|
20
|
-
def [] key
|
21
|
-
config = @config[key]
|
22
|
-
raise Mongoid::Errors::NoSessionConfig.new(key) unless config
|
23
|
-
@clients[key] ||= ClientFactory.create(config)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class ClientFactory
|
28
|
-
def self.create configuration
|
29
|
-
raise unless configuration
|
30
|
-
if configuration[:uri]
|
31
|
-
Mongo::Client.new(configuration[:uri], options(configuration))
|
32
|
-
else
|
33
|
-
opts = options(configuration).merge(database: configuration[:database])
|
34
|
-
opts = opts.merge(credentials(configuration))
|
35
|
-
Mongo::Client.new(configuration[:hosts], opts)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def self.options(configuration)
|
42
|
-
config = configuration.dup
|
43
|
-
options = config.delete(:options) || {}
|
44
|
-
options.reject{ |k, v| k == :hosts }.to_hash.symbolize_keys!
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.credentials(configuration)
|
48
|
-
details = {}
|
49
|
-
details[:user] = configuration[:username] unless configuration[:username].nil?
|
50
|
-
details[:password] = configuration[:password] unless configuration[:password].nil?
|
51
|
-
details
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class NoEnvironment < RuntimeError; end
|
56
|
-
# Encapsulates logic for getting environment information.
|
57
|
-
module Environment
|
58
|
-
extend self
|
59
|
-
|
60
|
-
# Get the name of the environment that we are running under. This first
|
61
|
-
# looks for Rails, then Sinatra, then a RACK_ENV environment variable,
|
62
|
-
# and if none of those are found raises an error.
|
63
|
-
#
|
64
|
-
# @example Get the env name.
|
65
|
-
# Environment.env_name
|
66
|
-
#
|
67
|
-
# @raise [ Errors::NoEnvironment ] If no environment was set.
|
68
|
-
#
|
69
|
-
# @return [ String ] The name of the current environment.
|
70
|
-
#
|
71
|
-
# @since 2.3.0
|
72
|
-
def env_name
|
73
|
-
return Rails.env if defined?(Rails) && Rails.respond_to?(:env)
|
74
|
-
return Sinatra::Base.environment.to_s if defined?(Sinatra)
|
75
|
-
ENV["RACK_ENV"] || ENV["MONGOID_ENV"] || raise(NoEnvironment.new)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Load the yaml from the provided path and return the settings for the
|
79
|
-
# current environment.
|
80
|
-
#
|
81
|
-
# @example Load the yaml.
|
82
|
-
# Environment.load_yaml("/work/mongoid.yml")
|
83
|
-
#
|
84
|
-
# @param [ String ] path The location of the file.
|
85
|
-
#
|
86
|
-
# @return [ Hash ] The settings.
|
87
|
-
#
|
88
|
-
# @since 2.3.0
|
89
|
-
def load_yaml(path, environment = nil)
|
90
|
-
env = environment ? environment.to_s : env_name
|
91
|
-
YAML.load(ERB.new(File.new(path).read).result)[env]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
data/spec/testapp/app.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
|
3
|
-
class SinatraApp < Sinatra::Base
|
4
|
-
# This prevents Sinatra from using the default logger.
|
5
|
-
set :logging, nil
|
6
|
-
|
7
|
-
get '/' do
|
8
|
-
puts logger.class.name
|
9
|
-
logger.debug 'Logging from Sinatra!'
|
10
|
-
|
11
|
-
"Log test on Sinatra #{Sinatra::VERSION}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
data/spec/testapp/config.ru
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rack/builder'
|
2
|
-
require 'mongo_request_logger'
|
3
|
-
require './app'
|
4
|
-
require 'rack/cascade'
|
5
|
-
|
6
|
-
app = Rack::Builder.new do
|
7
|
-
use Rack::Session::Cookie, secret: 'phungah1Geik8Eeth4Eezoh0aj1naeV2oiroh4EZe6Ulei1ohdooxae8cu0amake'
|
8
|
-
|
9
|
-
MongoRequestLogger.configure(File.join(File.dirname(__FILE__), 'config/logger.yml'))
|
10
|
-
use MongoRequestLogger::Rack
|
11
|
-
|
12
|
-
map "/log" do
|
13
|
-
run MongoRequestLogger::Viewer.new
|
14
|
-
end
|
15
|
-
|
16
|
-
map "/" do
|
17
|
-
run SinatraApp.new
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
run app
|
data/spec/testapp/log/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
*.log
|
data/spec/testapp/log/.gitkeep
DELETED
File without changes
|