mongodb_logger 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/mongodb_logger/adapters/moped.rb +6 -2
- data/lib/mongodb_logger/logger.rb +50 -32
- data/lib/mongodb_logger/server_config.rb +0 -4
- data/lib/mongodb_logger/version.rb +1 -1
- data/mongodb_logger.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7463e7411319454a836c0d10ee7725c6d71fe02
|
4
|
+
data.tar.gz: b12df4c637b7ef4e9860789cf2bbd3ba6d79b2b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b88448aeb56f96356ded3c87f1881e734a862e52f5cbd7d95db5a27b2187f8673845993051d367939b46e1737fc443dde90abea297f2725457839fe9c457cfc8
|
7
|
+
data.tar.gz: 5461c6c9af82e8fd914b596a7aebcc3b81e6827b6d44ab0edc5af0e83f077b73f09ccfe5666eb0e0f21472ba120756639101859f8ce5ef7bce0bcd9cdc1176df
|
data/.travis.yml
CHANGED
@@ -2,6 +2,7 @@ language: ruby
|
|
2
2
|
before_install:
|
3
3
|
- "export DISPLAY=:99.0"
|
4
4
|
- "sh -e /etc/init.d/xvfb start"
|
5
|
+
- gem install bundler --pre
|
5
6
|
before_script:
|
6
7
|
- bundle exec rake appraisal:install
|
7
8
|
services:
|
@@ -10,9 +11,17 @@ rvm:
|
|
10
11
|
- 1.9.3
|
11
12
|
- 2.0.0
|
12
13
|
- 2.1.0
|
14
|
+
- jruby-19mode
|
15
|
+
- ruby-head
|
16
|
+
- jruby-head
|
13
17
|
notifications:
|
14
18
|
email: false
|
15
19
|
branches:
|
16
20
|
only:
|
17
21
|
- master
|
18
22
|
- development
|
23
|
+
matrix:
|
24
|
+
allow_failures:
|
25
|
+
- rvm: jruby-19mode
|
26
|
+
- rvm: ruby-head
|
27
|
+
- rvm: jruby-head
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -289,4 +289,4 @@ Demo Sources: [https://github.com/le0pard/mongodb_logger_example_heroku](https:/
|
|
289
289
|
>> collection.find({:request_time => {'$gt' => Time.utc(2010, 11, 18, 22, 59, 52)}})
|
290
290
|
|
291
291
|
|
292
|
-
Copyright (c) 2009-
|
292
|
+
Copyright (c) 2009-2014 Phil Burrows, CustomInk (based on https://github.com/customink/central_logger) and Leopard released under the MIT license
|
@@ -26,7 +26,7 @@ module MongodbLogger
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def insert_log_record(record, options = {})
|
29
|
-
record[:_id] =
|
29
|
+
record[:_id] = bson_object_id.new
|
30
30
|
@connection.with(write: options[:write_options])[collection_name].insert(record)
|
31
31
|
end
|
32
32
|
|
@@ -46,7 +46,7 @@ module MongodbLogger
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def find_by_id(id)
|
49
|
-
@collection.find("_id" =>
|
49
|
+
@collection.find("_id" => bson_object_id.from_string(id)).first
|
50
50
|
end
|
51
51
|
|
52
52
|
def calculate_mapreduce(map, reduce, params = {})
|
@@ -75,6 +75,10 @@ module MongodbLogger
|
|
75
75
|
conn
|
76
76
|
end
|
77
77
|
|
78
|
+
def bson_object_id
|
79
|
+
defined?(::BSON::ObjectId) ? ::BSON::ObjectId : ::Moped::BSON::ObjectId
|
80
|
+
end
|
81
|
+
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
@@ -17,8 +17,8 @@ module MongodbLogger
|
|
17
17
|
LOG_LEVEL_SYM = [:debug, :info, :warn, :error, :fatal, :unknown]
|
18
18
|
|
19
19
|
ADAPTERS = [
|
20
|
-
["
|
21
|
-
["
|
20
|
+
["mongo", Adapers::Mongo],
|
21
|
+
["moped", Adapers::Moped]
|
22
22
|
]
|
23
23
|
|
24
24
|
attr_reader :db_configuration, :mongo_adapter, :app_root, :app_env
|
@@ -56,10 +56,7 @@ module MongodbLogger
|
|
56
56
|
def add(severity, message = nil, progname = nil, &block)
|
57
57
|
$stdout.puts(message) if ENV['HEROKU_RACK'] # log in stdout on Heroku
|
58
58
|
if @level && @level <= severity && (message.present? || progname.present?) && @mongo_record.present?
|
59
|
-
|
60
|
-
msg = (message ? message : progname)
|
61
|
-
msg = logging_colorized? ? msg.to_s.gsub(/(\e(\[([\d;]*[mz]?))?)?/, '').strip : msg
|
62
|
-
@mongo_record[:messages][LOG_LEVEL_SYM[severity]] << msg
|
59
|
+
add_log_message(severity, message, progname)
|
63
60
|
end
|
64
61
|
# may modify the original message
|
65
62
|
disable_file_logging? ? message : (@level ? super : message)
|
@@ -74,9 +71,7 @@ module MongodbLogger
|
|
74
71
|
|
75
72
|
runtime = Benchmark.measure{ yield }.real if block_given?
|
76
73
|
rescue Exception => e
|
77
|
-
|
78
|
-
# log exceptions
|
79
|
-
@mongo_record[:is_exception] = true
|
74
|
+
log_raised_error(e)
|
80
75
|
# Reraise the exception for anyone else who cares
|
81
76
|
raise e
|
82
77
|
ensure
|
@@ -84,19 +79,7 @@ module MongodbLogger
|
|
84
79
|
@mongo_record[:runtime] = ((runtime ||= 0) * 1000).ceil
|
85
80
|
# error callback
|
86
81
|
Base.on_log_exception(@mongo_record) if @mongo_record[:is_exception]
|
87
|
-
|
88
|
-
@insert_block.call
|
89
|
-
rescue
|
90
|
-
begin
|
91
|
-
# try to nice serialize record
|
92
|
-
record_serializer @mongo_record, true
|
93
|
-
@insert_block.call
|
94
|
-
rescue
|
95
|
-
# do extra work to inspect (and flatten)
|
96
|
-
record_serializer @mongo_record, false
|
97
|
-
@insert_block.call rescue nil
|
98
|
-
end
|
99
|
-
end
|
82
|
+
ensure_write_to_mongodb
|
100
83
|
end
|
101
84
|
|
102
85
|
def excluded_from_log
|
@@ -116,11 +99,10 @@ module MongodbLogger
|
|
116
99
|
end
|
117
100
|
|
118
101
|
def configure
|
119
|
-
default_capsize = DEFAULT_COLLECTION_SIZE
|
120
102
|
@db_configuration = {
|
121
103
|
host: 'localhost',
|
122
104
|
port: 27017,
|
123
|
-
capsize:
|
105
|
+
capsize: DEFAULT_COLLECTION_SIZE,
|
124
106
|
ssl: false}.merge(resolve_config).with_indifferent_access
|
125
107
|
@db_configuration[:collection] ||= "#{app_env}_log"
|
126
108
|
@db_configuration[:application_name] ||= resolve_application_name
|
@@ -132,22 +114,58 @@ module MongodbLogger
|
|
132
114
|
end
|
133
115
|
|
134
116
|
def resolve_application_name
|
135
|
-
|
117
|
+
if defined?(Rails)
|
118
|
+
Rails.application.class.to_s.split("::").first
|
119
|
+
else
|
120
|
+
"RackApp"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def add_log_message(severity, message, progname)
|
125
|
+
# do not modify the original message used by the buffered logger
|
126
|
+
msg = (message ? message : progname)
|
127
|
+
msg = logging_colorized? ? msg.to_s.gsub(/(\e(\[([\d;]*[mz]?))?)?/, '').strip : msg
|
128
|
+
@mongo_record[:messages][LOG_LEVEL_SYM[severity]] << msg
|
129
|
+
end
|
130
|
+
|
131
|
+
def log_raised_error(e)
|
132
|
+
add(3, "#{e.message}\n#{e.backtrace.join("\n")}")
|
133
|
+
# log exceptions
|
134
|
+
@mongo_record[:is_exception] = true
|
135
|
+
end
|
136
|
+
|
137
|
+
def ensure_write_to_mongodb
|
138
|
+
@insert_block.call
|
139
|
+
rescue
|
140
|
+
begin
|
141
|
+
# try to nice serialize record
|
142
|
+
record_serializer @mongo_record, true
|
143
|
+
@insert_block.call
|
144
|
+
rescue
|
145
|
+
# do extra work to inspect (and flatten)
|
146
|
+
record_serializer @mongo_record, false
|
147
|
+
@insert_block.call rescue nil
|
148
|
+
end
|
136
149
|
end
|
137
150
|
|
138
151
|
def resolve_config
|
139
152
|
config = {}
|
140
153
|
CONFIGURATION_FILES.each do |filename|
|
141
|
-
|
142
|
-
|
143
|
-
config = YAML.load(ERB.new(File.new(config_file).read).result)[app_env]
|
144
|
-
config = config['mongodb_logger'] if config && config.has_key?('mongodb_logger')
|
145
|
-
break unless config.blank?
|
146
|
-
end
|
154
|
+
config = read_config_from_file(File.join(app_root, 'config', filename))
|
155
|
+
break unless config.blank?
|
147
156
|
end
|
148
157
|
config
|
149
158
|
end
|
150
159
|
|
160
|
+
def read_config_from_file(config_file)
|
161
|
+
if File.file? config_file
|
162
|
+
config = YAML.load(ERB.new(File.new(config_file).read).result)[app_env]
|
163
|
+
config = config['mongodb_logger'] if config && config.has_key?('mongodb_logger')
|
164
|
+
return config unless config.blank?
|
165
|
+
end
|
166
|
+
return nil
|
167
|
+
end
|
168
|
+
|
151
169
|
def find_adapter
|
152
170
|
return Adapers::Mongo if defined?(::Mongo)
|
153
171
|
return Adapers::Moped if defined?(::Moped)
|
@@ -221,7 +239,7 @@ module MongodbLogger
|
|
221
239
|
elsif defined? RACK_ROOT
|
222
240
|
@app_root, @app_env = RACK_ROOT, (ENV['RACK_ENV'] || 'production')
|
223
241
|
else
|
224
|
-
|
242
|
+
@app_root, @app_env = File.dirname(__FILE__), 'production'
|
225
243
|
end
|
226
244
|
end
|
227
245
|
|
data/mongodb_logger.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_development_dependency "aruba", "~> 0.5.4"
|
24
24
|
# for tests deps
|
25
25
|
gem.add_development_dependency "coffee-script", "~> 2.2"
|
26
|
-
gem.add_development_dependency "rails", ">= 3.1.0"
|
27
26
|
gem.add_development_dependency "mongo", "~> 1.9"
|
28
27
|
#gem.add_development_dependency "moped", "2.0.0.beta6"
|
29
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongodb_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Vasiliev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -122,20 +122,6 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '2.2'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rails
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 3.1.0
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 3.1.0
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: mongo
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|