relevance-log_buddy 0.2.2 → 0.4.9

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/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.4.9 Added gem logging for debugging help when tracking down Gem activation errors
2
+
3
+ v0.2.3 Updating Micronaut
4
+
1
5
  v0.2.0. Better log output of objects based on their type, very similar to Logger/irb behavior; update to micronaut 0.1.0
2
6
 
3
7
  v0.1.5. Clean up specs and remove noise from spec run
data/Manifest CHANGED
@@ -1,10 +1,12 @@
1
1
  CHANGELOG
2
- examples/example_helper.rb
3
- examples/log_buddy_example.rb
4
- examples/log_buddy_init_example.rb
5
- examples/log_example.rb
2
+ examples/log_buddy/example_helper.rb
3
+ examples/log_buddy/gem_logger_example.rb
4
+ examples/log_buddy/log_buddy_example.rb
5
+ examples/log_buddy/log_buddy_init_example.rb
6
+ examples/log_buddy/log_example.rb
6
7
  examples.rb
7
8
  init.rb
9
+ lib/log_buddy/gem_logger.rb
8
10
  lib/log_buddy/mixin.rb
9
11
  lib/log_buddy/utils.rb
10
12
  lib/log_buddy/version.rb
data/README.rdoc CHANGED
@@ -8,7 +8,7 @@ log_buddy is your friendly little log buddy at your side, helping you dev, debug
8
8
 
9
9
  Require the init.rb file to use log_buddy. By default, it will add two methods to every object at the instance and class level: "d" and "logger". To use log_buddy without the automatic object intrusion, set ENV["SAFE_LOG_BUDDY"] = true before requiring the init.rb.
10
10
 
11
- You can use your own logger with Logbuddy by passing it into init's options hash:
11
+ You can use your own logger with LogBuddy by passing it into init's options hash:
12
12
 
13
13
  LogBuddy.init :default_logger => Logger.new('my_log.log')
14
14
 
@@ -38,6 +38,10 @@ in the block and the result. Examples:
38
38
 
39
39
  See examples.rb for live examples you can run.
40
40
 
41
+ When you occasionally want to disable LogBuddy (but you don't want to have to remove all your debug statements), you can pass the :disabled option into init's options hash:
42
+
43
+ LogBuddy.init :disabled => true
44
+
41
45
  == REQUIREMENTS:
42
46
 
43
47
  * Ruby 1.8.6 or JRuby (tested with 1.1RC3)
@@ -64,7 +68,7 @@ See examples.rb for live examples you can run.
64
68
 
65
69
  (The MIT License)
66
70
 
67
- Copyright (c) 2008 Relevance, Inc. - http://thinkrelevance.com
71
+ Copyright (c) 2009 Relevance, Inc. - http://thinkrelevance.com
68
72
 
69
73
  Permission is hereby granted, free of charge, to any person obtaining
70
74
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'rubygems'
2
2
  gem 'echoe'
3
+ gem "spicycode-micronaut", ">= 0.2.0"
3
4
  require 'echoe'
5
+ require 'micronaut'
6
+ require 'micronaut/rake_task'
4
7
  require File.join(File.dirname(__FILE__), *%w[lib log_buddy version])
5
8
 
6
9
  echoe = Echoe.new('log_buddy', LogBuddy::VERSION::STRING) do |p|
@@ -18,25 +21,18 @@ end
18
21
  Rake.application.instance_variable_get(:@tasks).delete("default")
19
22
  Rake.application.instance_variable_get(:@tasks).delete("test")
20
23
 
21
- namespace :micronaut do
22
-
23
- desc 'Run all examples'
24
- task :examples do
25
- examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
26
- examples.map! {|f| %Q(require "#{f}")}
27
- command = "-e '#{examples.join("; ")}'"
28
- ruby command
29
- end
30
-
24
+ desc "Run all examples"
25
+ Micronaut::RakeTask.new(:examples)
26
+
27
+ namespace :examples do
31
28
  desc "Run all examples using rcov"
32
- task :coverage do
33
- examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
34
- system "rcov --exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-report --sort coverage --no-validator-links #{examples.join(' ')}"
29
+ Micronaut::RakeTask.new :coverage do |t|
30
+ t.rcov = true
31
+ t.rcov_opts = %[--exclude "gems/*,/Library/Ruby/*,config/*" --text-summary --sort coverage --no-validator-links]
35
32
  end
36
-
37
33
  end
38
34
 
39
- task :default => 'micronaut:coverage'
35
+ task :default => 'examples:coverage'
40
36
 
41
37
  # The below results in 'input stream exhausted' - dunno why?
42
38
  # task :release => [:test, :publish_docs, :announce]
@@ -1,10 +1,10 @@
1
1
  require 'logger'
2
2
  require 'rubygems'
3
- gem 'spicycode-micronaut', "~> 0.1.5"
3
+ gem "spicycode-micronaut", ">= 0.2.0"
4
4
  gem 'mocha'
5
5
  require "mocha"
6
6
  require 'micronaut'
7
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "log_buddy"))
7
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "log_buddy"))
8
8
 
9
9
  def silence_warnings
10
10
  old_verbose, $VERBOSE = $VERBOSE, nil
@@ -15,6 +15,7 @@ end
15
15
 
16
16
  Micronaut.configure do |config|
17
17
  config.mock_with :mocha
18
+ config.formatter = :documentation
19
+ config.color_enabled = true
18
20
  config.filter_run :options => { :focused => true }
19
- config.autorun!
20
21
  end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), *%w[example_helper]))
2
+
3
+ describe LogBuddy::GemLogger do
4
+
5
+ describe "starting Gem logging" do
6
+
7
+ it "includes GemLogger into Gem when #log_gems! is called" do
8
+ Gem.expects(:include).with(LogBuddy::GemLogger)
9
+ LogBuddy::GemLogger.log_gems!
10
+ end
11
+
12
+ end
13
+
14
+ describe "Gem#activation monkey patching for logging" do
15
+
16
+ before do
17
+ LogBuddy.init
18
+ LogBuddy::GemLogger.log_gems!
19
+ end
20
+
21
+ it "should log the gem name and version and where it was called from" do
22
+ Gem.stubs(:activate_without_logging)
23
+
24
+ LogBuddy.expects(:debug).with do |msg|
25
+ msg.should include(%[Gem activation for gem: 'gem-name' version: '0.5' called from:\n])
26
+ gem_calling_line = __LINE__ + 3
27
+ msg.should include(%[examples/log_buddy/gem_logger_example.rb:#{gem_calling_line}])
28
+ end
29
+ gem "gem-name", "0.5"
30
+ end
31
+
32
+ it "should do the original gem activation call" do
33
+ LogBuddy.stubs(:debug)
34
+ Gem.expects(:activate_without_logging).with('gem-name', ">= 1.0.0")
35
+ gem "gem-name", ">= 1.0.0"
36
+ end
37
+
38
+ it "should add alias gem_without_logging" do
39
+ Gem.should respond_to(:activate)
40
+ Gem.should respond_to(:activate_without_logging)
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -4,6 +4,11 @@ describe LogBuddy do
4
4
  describe "init" do
5
5
  after { reset_safe_log_buddy_mode }
6
6
 
7
+ it "should call log_gems! if log_gems is true" do
8
+ LogBuddy::GemLogger.expects(:log_gems!)
9
+ LogBuddy.init :log_gems => true
10
+ end
11
+
7
12
  it "doesnt mixin to object if SAFE_LOG_BUDDY is true" do
8
13
  LogBuddy.expects(:init).never
9
14
  ENV["SAFE_LOG_BUDDY"] = "true"
@@ -17,7 +22,7 @@ describe LogBuddy do
17
22
 
18
23
  def load_init
19
24
  silence_warnings do
20
- load File.join(File.dirname(__FILE__), *%w[.. init.rb])
25
+ load File.join(File.dirname(__FILE__), *%w[.. .. init.rb])
21
26
  end
22
27
  end
23
28
 
@@ -25,6 +30,13 @@ describe LogBuddy do
25
30
  ENV["SAFE_LOG_BUDDY"] = nil
26
31
  end
27
32
 
33
+ it "should be disabled when the :disabled key is true" do
34
+ LogBuddy.init(:disabled => true)
35
+ fake_logger = mock('logger')
36
+ LogBuddy.stubs(:logger).returns(fake_logger)
37
+ fake_logger.expects(:debug).never
38
+ d { "Hello, World!" }
39
+ end
28
40
  end
29
41
 
30
42
  end
@@ -0,0 +1,24 @@
1
+ module LogBuddy
2
+ module GemLogger
3
+
4
+ BACKTRACE_SIZE = 0..5
5
+
6
+ def self.log_gems!
7
+ Gem.send :include, LogBuddy::GemLogger
8
+ end
9
+
10
+ def self.included(mod)
11
+
12
+ class << mod
13
+ def activate_with_logging(gem, *version_requirements)
14
+ d %[Gem activation for gem: '#{gem}' version: '#{version_requirements}' called from:\n#{caller[BACKTRACE_SIZE].join("\n")}]
15
+ activate_without_logging(gem, *version_requirements)
16
+ end
17
+
18
+ alias_method :activate_without_logging, :activate
19
+ alias_method :activate, :activate_with_logging
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,7 @@ module LogBuddy
2
2
  module Utils
3
3
 
4
4
  def debug(obj)
5
+ return if @disabled
5
6
  str = obj_to_string(obj)
6
7
  stdout_puts(str) if log_to_stdout?
7
8
  logger.debug(str)
@@ -1,8 +1,8 @@
1
1
  module LogBuddy
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 2
5
- TINY = 2
4
+ MINOR = 4
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/log_buddy.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[log_buddy utils])
2
2
  require File.join(File.dirname(__FILE__), *%w[log_buddy mixin])
3
+ require File.join(File.dirname(__FILE__), *%w[log_buddy gem_logger])
3
4
  require File.join(File.dirname(__FILE__), *%w[log_buddy version])
4
5
 
5
6
  =begin rdoc
@@ -26,10 +27,15 @@ module LogBuddy
26
27
  # * <tt>:logger</tt> - the logger instance that LogBuddy should use (if not provided,
27
28
  # tries to default to RAILS_DEFAULT_LOGGER, and then to a STDOUT logger).
28
29
  # * <tt):log_to_stdout</tt> - whether LogBuddy should _also_ log to STDOUT, very helpful for Autotest (default is +true+).
30
+ # * <tt>:disabled</tt> - when true, LogBuddy will not produce any output
31
+ # * <tt>:log_gems</tt> - log Gem activation process - useful for tracking down Gem activation errors (default is +false+)
29
32
  def self.init(options = {})
30
33
  @logger = options[:logger]
31
34
  @log_to_stdout = options.has_key?(:log_to_stdout) ? options[:log_to_stdout] : true
35
+ @log_gems = options[:log_gems]
36
+ @disabled = (options[:disabled] == true)
32
37
  mixin_to_object
38
+ GemLogger.log_gems! if @log_gems
33
39
  end
34
40
 
35
41
  # Add the LogBuddy::Mixin to Object instance and class level.
data/log_buddy.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{log_buddy}
5
- s.version = "0.2.2"
5
+ s.version = "0.4.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Rob Sanheim - Relevance"]
9
- s.date = %q{2008-12-23}
9
+ s.date = %q{2009-01-19}
10
10
  s.description = %q{Log statements along with their name easily. Mixin a logger everywhere when you need it.}
11
11
  s.email = %q{opensource@thinkrelevance.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/log_buddy/mixin.rb", "lib/log_buddy/utils.rb", "lib/log_buddy/version.rb", "lib/log_buddy.rb", "LICENSE", "log_buddy.gemspec", "README.rdoc"]
13
- s.files = ["CHANGELOG", "examples/example_helper.rb", "examples/log_buddy_example.rb", "examples/log_buddy_init_example.rb", "examples/log_example.rb", "examples.rb", "init.rb", "lib/log_buddy/mixin.rb", "lib/log_buddy/utils.rb", "lib/log_buddy/version.rb", "lib/log_buddy.rb", "LICENSE", "log_buddy.gemspec", "Manifest", "Rakefile", "README.rdoc"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/log_buddy/gem_logger.rb", "lib/log_buddy/mixin.rb", "lib/log_buddy/utils.rb", "lib/log_buddy/version.rb", "lib/log_buddy.rb", "LICENSE", "log_buddy.gemspec", "README.rdoc"]
13
+ s.files = ["CHANGELOG", "examples/log_buddy/example_helper.rb", "examples/log_buddy/gem_logger_example.rb", "examples/log_buddy/log_buddy_example.rb", "examples/log_buddy/log_buddy_init_example.rb", "examples/log_buddy/log_example.rb", "examples.rb", "init.rb", "lib/log_buddy/gem_logger.rb", "lib/log_buddy/mixin.rb", "lib/log_buddy/utils.rb", "lib/log_buddy/version.rb", "lib/log_buddy.rb", "LICENSE", "log_buddy.gemspec", "Manifest", "Rakefile", "README.rdoc"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/relevance/log_buddy}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Log_buddy", "--main", "README.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relevance-log_buddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Sanheim - Relevance
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-23 00:00:00 -08:00
12
+ date: 2009-01-19 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,7 @@ extensions: []
65
65
 
66
66
  extra_rdoc_files:
67
67
  - CHANGELOG
68
+ - lib/log_buddy/gem_logger.rb
68
69
  - lib/log_buddy/mixin.rb
69
70
  - lib/log_buddy/utils.rb
70
71
  - lib/log_buddy/version.rb
@@ -74,12 +75,14 @@ extra_rdoc_files:
74
75
  - README.rdoc
75
76
  files:
76
77
  - CHANGELOG
77
- - examples/example_helper.rb
78
- - examples/log_buddy_example.rb
79
- - examples/log_buddy_init_example.rb
80
- - examples/log_example.rb
78
+ - examples/log_buddy/example_helper.rb
79
+ - examples/log_buddy/gem_logger_example.rb
80
+ - examples/log_buddy/log_buddy_example.rb
81
+ - examples/log_buddy/log_buddy_init_example.rb
82
+ - examples/log_buddy/log_example.rb
81
83
  - examples.rb
82
84
  - init.rb
85
+ - lib/log_buddy/gem_logger.rb
83
86
  - lib/log_buddy/mixin.rb
84
87
  - lib/log_buddy/utils.rb
85
88
  - lib/log_buddy/version.rb