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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48c3b365b540c0fdf70f0e4526fb83bd7730a85a
4
- data.tar.gz: 3bbb2a8c14841e2adefa225549b959fd52914105
3
+ metadata.gz: f7463e7411319454a836c0d10ee7725c6d71fe02
4
+ data.tar.gz: b12df4c637b7ef4e9860789cf2bbd3ba6d79b2b6
5
5
  SHA512:
6
- metadata.gz: 9760b107a220bb5ddf047ba3e811173fc2775aaf7c6cb8966914ba7a3f202fac05326ffe9427efef78c93e42ab99a2f8004fc4923bdd7d0924556d6c87d3f610
7
- data.tar.gz: e961c5158423d113e0b09b2d099bf67a8e67d969a0235cf65b587608eb54753d4fbc5727cd1b6cbfbd3043d64609b34bebd0a79d42de1214342760636a1b7c76
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
@@ -1,5 +1,8 @@
1
1
  ## master
2
2
 
3
+ ## 0.6.4
4
+
5
+ * Fixed for moped gem < 2
3
6
 
4
7
  ## 0.6.3
5
8
 
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-2012 Phil Burrows, CustomInk (based on https://github.com/customink/central_logger) and Leopard released under the MIT license
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] = ::BSON::ObjectId.new
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" => ::BSON::ObjectId.from_string(id)).first
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
- ["moped", Adapers::Moped],
21
- ["mongo", Adapers::Mongo]
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
- # do not modify the original message used by the buffered logger
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
- add(3, "#{e.message}\n#{e.backtrace.join("\n")}")
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
- begin
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: default_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
- Rails.application.class.to_s.split("::").first if defined?(Rails)
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
- config_file = File.join(app_root, 'config', filename)
142
- if File.file? config_file
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
- raise "unknown app type: not Rails or Rack"
242
+ @app_root, @app_env = File.dirname(__FILE__), 'production'
225
243
  end
226
244
  end
227
245
 
@@ -11,10 +11,6 @@ module MongodbLogger
11
11
  config = config['mongodb_logger'] if config && config.has_key?('mongodb_logger')
12
12
  config
13
13
  end
14
-
15
- def set_root_and_env
16
- @app_root, @app_env = File.dirname(__FILE__), 'production'
17
- end
18
14
  end
19
15
 
20
16
  class << self
@@ -1,3 +1,3 @@
1
1
  module MongodbLogger
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -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.3
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-01 00:00:00.000000000 Z
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