central_logger 0.1.0 → 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.
data/README.md CHANGED
@@ -4,7 +4,11 @@ Log to a central MongoDB from Rails apps.
4
4
 
5
5
  ## Usage
6
6
 
7
- 1. Install the gem:
7
+ 1. If using Bundler, add the following to your Gemfile then refresh your dependencies by executing "bundle install":
8
+
9
+ gem "central_logger"
10
+
11
+ 1. If you're just using gem:
8
12
 
9
13
  gem install central_logger
10
14
 
@@ -12,13 +16,12 @@ Log to a central MongoDB from Rails apps.
12
16
 
13
17
  include CentralLogger::Filter
14
18
 
15
- 1. If using Rails < 3, configure environment.rb as shown below (in config/environment.rb). Otherwise, the logger is
16
- automatically initialized for all environments.
19
+ 1. If using Rails 3, SKIP this step. Otherwise, add the following to config/environment.rb:
17
20
 
18
21
  require 'central_logger'
19
22
  CentralLogger::Initializer.initialize_deprecated_logger(config)
20
23
 
21
- 1. Add mongo settings to database.yml for each environment in which you want to use MongoDB for logging. The values below are defaults:
24
+ 1. Add mongo settings to database.yml for each environment in which you want to use the Central Logger for logging. The values below are defaults:
22
25
 
23
26
  development:
24
27
  adapter: mysql
data/Rakefile CHANGED
@@ -24,10 +24,6 @@ Jeweler::Tasks.new do |gem|
24
24
  gem.email = "astupka@customink.com"
25
25
  gem.homepage = "http://github.com/customink/central_logger"
26
26
  gem.authors = ["Phil Burrows", "Alex Stupka"]
27
- gem.rubyforge_project = "central_logger"
28
- end
29
- Jeweler::RubyforgeTasks.new do |rubyforge|
30
- rubyforge.doc_task = "rdoc"
31
27
  end
32
28
  # dependencies defined in Gemfile
33
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{central_logger}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Phil Burrows", "Alex Stupka"]
12
- s.date = %q{2010-11-01}
12
+ s.date = %q{2010-11-03}
13
13
  s.description = %q{Centralized logging for rails apps using MongoDB. The idea and the core code is from http://github.com/peburrows/central_logger}
14
14
  s.email = %q{astupka@customink.com}
15
15
  s.extra_rdoc_files = [
@@ -39,7 +39,6 @@ Gem::Specification.new do |s|
39
39
  ]
40
40
  s.homepage = %q{http://github.com/customink/central_logger}
41
41
  s.require_paths = ["lib"]
42
- s.rubyforge_project = %q{central_logger}
43
42
  s.rubygems_version = %q{1.3.7}
44
43
  s.summary = %q{Central Logger for Rails}
45
44
  s.test_files = [
@@ -52,16 +52,15 @@ module CentralLogger
52
52
  :request_time => Time.now.getutc,
53
53
  :application_name => @application_name
54
54
  })
55
- # In case of exception, make sure it's set
56
- runtime = 0
57
- runtime = Benchmark.measure do
58
- yield
59
- end
55
+
56
+ runtime = Benchmark.measure{ yield }.real
60
57
  rescue Exception => e
61
58
  add(3, e.message + "\n" + e.backtrace.join("\n"))
62
59
  # Reraise the exception for anyone else who cares
63
60
  raise e
64
61
  ensure
62
+ # In case of exception, make sure runtime is set
63
+ runtime ||= 0
65
64
  insert_log_record(runtime)
66
65
  end
67
66
 
@@ -105,7 +104,7 @@ module CentralLogger
105
104
  end
106
105
 
107
106
  def insert_log_record(runtime)
108
- @mongo_record[:runtime] = (runtime.real * 1000).ceil
107
+ @mongo_record[:runtime] = (runtime * 1000).ceil
109
108
  @mongo_connection[@mongo_collection_name].insert(@mongo_record) rescue nil
110
109
  end
111
110
 
data/test/test_helper.rb CHANGED
@@ -17,6 +17,12 @@ class Test::Unit::TestCase
17
17
  end
18
18
  end
19
19
 
20
+ def log_exception(msg)
21
+ @central_logger.mongoize({"id" => 1}) do
22
+ raise msg
23
+ end
24
+ end
25
+
20
26
  def log_metadata(options)
21
27
  @central_logger.mongoize({"id" => 1}) do
22
28
  @central_logger.add_metadata(options)
@@ -5,6 +5,8 @@ require 'central_logger/mongo_logger'
5
5
  class CentralLogger::MongoLoggerTest < Test::Unit::TestCase
6
6
  extend LogMacros
7
7
 
8
+ EXCEPTION_MSG = "Foo"
9
+
8
10
  context "A CentralLogger::MongoLogger" do
9
11
  context "during configuration in instantiation" do
10
12
  setup do
@@ -47,6 +49,7 @@ class CentralLogger::MongoLoggerTest < Test::Unit::TestCase
47
49
  setup do
48
50
  @central_logger = CentralLogger::MongoLogger.new
49
51
  common_setup
52
+ @central_logger.reset_collection
50
53
  end
51
54
 
52
55
  context "upon insertion of a log record when active record is not used" do
@@ -67,7 +70,6 @@ class CentralLogger::MongoLoggerTest < Test::Unit::TestCase
67
70
  setup do
68
71
  @log_message = "TESTING"
69
72
  require_bogus_active_record
70
- @central_logger.reset_collection
71
73
  log("\e[31m #{@log_message} \e[0m")
72
74
  end
73
75
 
@@ -87,13 +89,20 @@ class CentralLogger::MongoLoggerTest < Test::Unit::TestCase
87
89
  log_metadata(options)
88
90
  assert_equal 1, @collection.find({"application" => self.class.name}).count
89
91
  end
92
+
93
+ context "when an exception is raised" do
94
+ should "log the exception" do
95
+ assert_raise(RuntimeError, EXCEPTION_MSG) {log_exception(EXCEPTION_MSG)}
96
+ assert_equal 1, @collection.find_one({"messages.error" => /^#{EXCEPTION_MSG}/})["messages"]["error"].count
97
+ end
98
+ end
90
99
  end
91
100
 
92
101
  context "logging at INFO level" do
93
102
  setup do
94
103
  @central_logger = CentralLogger::MongoLogger.new(:level => CentralLogger::MongoLogger::INFO)
95
- @central_logger.reset_collection
96
104
  common_setup
105
+ @central_logger.reset_collection
97
106
  log("INFO")
98
107
  end
99
108
 
@@ -103,5 +112,6 @@ class CentralLogger::MongoLoggerTest < Test::Unit::TestCase
103
112
  assert_equal 0, @collection.find_one({}, :fields => ["messages"])["messages"].count
104
113
  end
105
114
  end
115
+
106
116
  end
107
117
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Phil Burrows
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-01 00:00:00 -04:00
18
+ date: 2010-11-03 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  version: "0"
210
210
  requirements: []
211
211
 
212
- rubyforge_project: central_logger
212
+ rubyforge_project:
213
213
  rubygems_version: 1.3.7
214
214
  signing_key:
215
215
  specification_version: 3