-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jasonhutchens
committed
Jun 20, 2013
1 parent
7e16fb9
commit 7e1e89c
Showing
9 changed files
with
207 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source "http://rubygems.org" | ||
|
||
group :development do | ||
gem 'rspec', ">2.0.0" | ||
gem 'rake' | ||
gem 'jeweler' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
diff-lcs (1.1.2) | ||
git (1.2.5) | ||
jeweler (1.8.4) | ||
bundler (~> 1.0) | ||
git (>= 1.2.5) | ||
rake | ||
rdoc | ||
json (1.7.6) | ||
rake (10.0.3) | ||
rdoc (3.12) | ||
json (~> 1.4) | ||
rspec (2.5.0) | ||
rspec-core (~> 2.5.0) | ||
rspec-expectations (~> 2.5.0) | ||
rspec-mocks (~> 2.5.0) | ||
rspec-core (2.5.1) | ||
rspec-expectations (2.5.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-mocks (2.5.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
jeweler | ||
rake | ||
rspec (> 2.0.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
== Hodel 3000 Compliant Logger | ||
|
||
The Hodel 3000 Compliant Logger outputs like SyslogLogger (http://seattlerb.rubyforge.org/SyslogLogger/), except it doesn't need a syslog daemon running, such that your log come out exactly like syslog logs. | ||
|
||
Mostly, this is intended to let you use tools that assume your log are in this syslog format, including: | ||
|
||
* Rails Analyzer Tools: http://rails-analyzer.rubyforge.org/ | ||
* oink: http://github.com/noahd1/oink | ||
|
||
See initial announcement here: http://nubyonrails.com/articles/a-hodel-3000-compliant-logger-for-the-rest-of-us | ||
|
||
=== Installation and congiguration | ||
|
||
gem install hodel_3000_compliant_logger | ||
|
||
The main thing hodel_3000_complaint_logger provides is the Hodel3000ComplaintLogger class. It's a subclass of Logger (http://ruby-doc.org/core/classes/Logger.html), so you can use it as you would any Logger, really, except it outputs slightly different. | ||
|
||
require 'hodel_3000_compliant_logger' | ||
log = Hodel3000ComplaintLogger.new(STDOUT) | ||
log.level = Logger::WARN | ||
|
||
log.debug("Created logger") | ||
log.info("Program started") | ||
log.warn("Nothing to do!") | ||
|
||
To use hodel_3000_complaint_logger in Rails 3 as a replacement for the default logger, place the following line in your application.rb: | ||
|
||
config.logger = Hodel3000CompliantLogger.new(config.paths.log.first) | ||
|
||
In Rails 2, instead use the following in your environment.rb file: | ||
|
||
config.logger = Hodel3000CompliantLogger.new(config.paths.log.first) | ||
|
||
=== NOTE | ||
|
||
If you are using FastCGI, you may need to hard-code the hostname instead of using Socket.gethostname | ||
|
||
== Author | ||
|
||
Geoffrey Grosenbach, with help from Eric Hodel | ||
|
||
http://topfunky.com | ||
|
||
== Changes | ||
|
||
* Nov 29, 2007: Improvements and spec from Chris Bernard [http://logicleaf.com/] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
require 'rake' | ||
|
||
begin | ||
require 'jeweler' | ||
|
||
Jeweler::Tasks.new do |gem| | ||
gem.name = "hodel_3000_compliant_logger" | ||
gem.version = "0.1.1" | ||
gem.summary = %Q{Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.} | ||
gem.description = %Q{Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.} | ||
gem.email = "[email protected]" | ||
gem.homepage = "http://github.com/topfunky/hodel_3000_compliant_logger" | ||
gem.authors = ["Geoffrey Grosenbach"] | ||
gem.add_development_dependency "rspec", "~> 1.3.0" | ||
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings | ||
end | ||
|
||
Jeweler::GemcutterTasks.new | ||
rescue LoadError | ||
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" | ||
end | ||
|
||
require 'rspec/core/rake_task' | ||
|
||
desc 'Default: run specs.' | ||
task :default => :spec | ||
|
||
desc "Run specs" | ||
task :default do | ||
system "spec spec" | ||
end | ||
RSpec::Core::RakeTask.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Generated by jeweler | ||
# DO NOT EDIT THIS FILE DIRECTLY | ||
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' | ||
# -*- encoding: utf-8 -*- | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "hodel_3000_compliant_logger" | ||
s.version = "0.1.2" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Geoffrey Grosenbach"] | ||
s.date = "2013-01-03" | ||
s.description = "Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem." | ||
s.email = "[email protected]" | ||
s.extra_rdoc_files = [ | ||
"README.rdoc" | ||
] | ||
s.files = [ | ||
".rspec", | ||
"Gemfile", | ||
"Gemfile.lock", | ||
"README.rdoc", | ||
"Rakefile", | ||
"hodel_3000_compliant_logger.gemspec", | ||
"lib/hodel_3000_compliant_logger.rb", | ||
"spec/hodel_3000_compliant_logger_spec.rb" | ||
] | ||
s.homepage = "http://github.com/topfunky/hodel_3000_compliant_logger" | ||
s.require_paths = ["lib"] | ||
s.rubygems_version = "1.8.24" | ||
s.summary = "Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem." | ||
|
||
if s.respond_to? :specification_version then | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then | ||
s.add_development_dependency(%q<rspec>, ["> 2.0.0"]) | ||
s.add_development_dependency(%q<rake>, [">= 0"]) | ||
s.add_development_dependency(%q<jeweler>, [">= 0"]) | ||
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"]) | ||
else | ||
s.add_dependency(%q<rspec>, ["> 2.0.0"]) | ||
s.add_dependency(%q<rake>, [">= 0"]) | ||
s.add_dependency(%q<jeweler>, [">= 0"]) | ||
s.add_dependency(%q<rspec>, ["~> 1.3.0"]) | ||
end | ||
else | ||
s.add_dependency(%q<rspec>, ["> 2.0.0"]) | ||
s.add_dependency(%q<rake>, [">= 0"]) | ||
s.add_dependency(%q<jeweler>, [">= 0"]) | ||
s.add_dependency(%q<rspec>, ["~> 1.3.0"]) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
$: << File.dirname(__FILE__) + "/../lib" | ||
|
||
require 'rubygems' | ||
require 'spec' | ||
require 'rspec' | ||
require 'hodel_3000_compliant_logger' | ||
require 'stringio' | ||
|
||
describe Hodel3000CompliantLogger do | ||
|
||
before :each do | ||
@out = StringIO.new | ||
@log = Hodel3000CompliantLogger.new(@out) | ||
end | ||
|
||
it "should log stuff in a syslog-like format so that Eric Hodel's Rails Analyzer Tools can parse it" do | ||
msg = "Yo ho hello there!" | ||
@log.info(msg) | ||
@out.string.should match(/^\w{3} \d{2} \d{2}:\d{2}:\d{2} \w+ rails\[\d+\]: #{msg}\n$/) | ||
end | ||
|
||
it "should handle an Exception object used as an argument in Logger#error, rather than blow chunks" do | ||
@log.error(Exception.new) | ||
@out.string.should match(/Exception/) | ||
end | ||
|
||
it "should display a semi-readable stack trace (albiet on one line) when Logger#error(SomeException) was called" do | ||
@log.error(toss_runtime_error) | ||
@out.string.should match(/.*? \| .*? \| .*? \|/) # pipe separated stack frames | ||
@out.string.should match(/\n$/) | ||
@out.string.count("\n").should == 1 | ||
end | ||
|
||
def toss_runtime_error | ||
raise "Catastrophic Failure" | ||
rescue => e | ||
return e | ||
end | ||
describe Hodel3000CompliantLogger do | ||
|
||
before :each do | ||
@out = StringIO.new | ||
@log = Hodel3000CompliantLogger.new(@out) | ||
Socket.stub(:gethostname).and_return('hostname.domain') | ||
end | ||
|
||
it "should log stuff in a syslog-like format so that Eric Hodel's Rails Analyzer Tools can parse it" do | ||
msg = "Yo ho hello there!" | ||
@log.info(msg) | ||
@out.string.should match(/^\w{3} \d{2} \d{2}:\d{2}:\d{2} hostname rails\[\d+|\d+\]: #{msg}\n$/) | ||
end | ||
|
||
it "should handle an Exception object used as an argument in Logger#error, rather than blow chunks" do | ||
@log.error(Exception.new) | ||
@out.string.should match(/Exception/) | ||
end | ||
|
||
it "should display a semi-readable stack trace (albiet on one line) when Logger#error(SomeException) was called" do | ||
@log.error(toss_runtime_error) | ||
@out.string.should match(/.*? \| .*? \| .*? \|/) # pipe separated stack frames | ||
@out.string.should match(/\n$/) | ||
@out.string.count("\n").should == 1 | ||
end | ||
|
||
it "should replace newlines in message with an empty string" do | ||
msg = "Yo\nho\nhello\nthere!" | ||
@log.info(msg) | ||
@out.string.should match(/^\w{3} \d{2} \d{2}:\d{2}:\d{2} hostname rails\[\d+:\d+\]: Yohohellothere!\n$/) | ||
end | ||
|
||
def toss_runtime_error | ||
raise "Catastrophic Failure" | ||
rescue => e | ||
return e | ||
end | ||
end | ||
|