hodel_3000_compliant_logger 0.1.0
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.rdoc +52 -0
- data/Rakefile +27 -0
- data/hodel_3000_compliant_logger.gemspec +47 -0
- data/lib/hodel_3000_compliant_logger.rb +31 -0
- data/spec/hodel_3000_compliant_logger_spec.rb +39 -0
- metadata +86 -0
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
== Hodel 3000 Compliant Logger
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
Mostly, this is intended to let you use tools that assume your log are in this syslog format, including:
|
6
|
+
|
7
|
+
* Rails Analyzer Tools: http://rails-analyzer.rubyforge.org/
|
8
|
+
* oink: http://github.com/noahd1/oink
|
9
|
+
|
10
|
+
See initial announcement here: http://nubyonrails.com/articles/a-hodel-3000-compliant-logger-for-the-rest-of-us
|
11
|
+
|
12
|
+
=== Installation and congiguration
|
13
|
+
|
14
|
+
gem install hodel_3000_compliant_logger
|
15
|
+
|
16
|
+
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.
|
17
|
+
|
18
|
+
require 'hodel_3000_compliant_logger'
|
19
|
+
log = Hodel3000ComplaintLogger.new(STDOUT)
|
20
|
+
log.level = Logger::WARN
|
21
|
+
|
22
|
+
log.debug("Created logger")
|
23
|
+
log.info("Program started")
|
24
|
+
log.warn("Nothing to do!")
|
25
|
+
|
26
|
+
Most likely, you'll want to use it to replace the builtin Rails logger, by updating config/environment.rb:
|
27
|
+
|
28
|
+
Rails::Initializer.run do |config|
|
29
|
+
config.gem 'hodel_3000_compliant_logger'
|
30
|
+
begin
|
31
|
+
require 'hodel_3000_compliant_logger'
|
32
|
+
config.logger = Hodel3000CompliantLogger.new(config.log_path)
|
33
|
+
rescue
|
34
|
+
$stderr.puts "Hodel3000CompliantLogger unavailable, oink will be disabled"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Note, the block inside Rails::Initializer runs before you environment is fully loaded, so you need this in a begin/rescue block so `rake gems:install` doesn't fall on its face.
|
39
|
+
|
40
|
+
=== NOTE
|
41
|
+
|
42
|
+
If you are using FastCGI, you may need to hard-code the hostname instead of using Socket.gethostname
|
43
|
+
|
44
|
+
== Author
|
45
|
+
|
46
|
+
Geoffrey Grosenbach, with help from Eric Hodel
|
47
|
+
|
48
|
+
http://topfunky.com
|
49
|
+
|
50
|
+
== Changes
|
51
|
+
|
52
|
+
* Nov 29, 2007: Improvements and spec from Chris Bernard [http://logicleaf.com/]
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "hodel_3000_compliant_logger"
|
8
|
+
gem.version = "0.1.0"
|
9
|
+
gem.summary = %Q{Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.}
|
10
|
+
gem.description = %Q{Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.}
|
11
|
+
gem.email = "boss@topfunky.com"
|
12
|
+
gem.homepage = "http://github.com/topfunky/hodel_3000_compliant_logger"
|
13
|
+
gem.authors = ["Geoffrey Grosenbach"]
|
14
|
+
gem.add_development_dependency "rspec", "~> 1.3.0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
task :default => :spec
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hodel_3000_compliant_logger}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Geoffrey Grosenbach"]
|
12
|
+
s.date = %q{2010-09-30}
|
13
|
+
s.description = %q{Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.}
|
14
|
+
s.email = %q{boss@topfunky.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"hodel_3000_compliant_logger.gemspec",
|
22
|
+
"lib/hodel_3000_compliant_logger.rb",
|
23
|
+
"spec/hodel_3000_compliant_logger_spec.rb"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/topfunky/hodel_3000_compliant_logger}
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubygems_version = %q{1.3.7}
|
29
|
+
s.summary = %q{Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.}
|
30
|
+
s.test_files = [
|
31
|
+
"spec/hodel_3000_compliant_logger_spec.rb"
|
32
|
+
]
|
33
|
+
|
34
|
+
if s.respond_to? :specification_version then
|
35
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
36
|
+
s.specification_version = 3
|
37
|
+
|
38
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
39
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'English'
|
3
|
+
|
4
|
+
# A logger for use with pl_analyze and other tools that expect syslog-style log output.
|
5
|
+
class Hodel3000CompliantLogger < Logger
|
6
|
+
|
7
|
+
##
|
8
|
+
# Note: If you are using FastCGI you may need to hard-code the hostname here instead of using Socket.gethostname
|
9
|
+
def format_message(severity, timestamp, progname, msg)
|
10
|
+
"#{timestamp.strftime("%b %d %H:%M:%S")} #{hostname} rails[#{$PID}]: #{msg2str(msg).gsub(/\n/, '').lstrip}\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def hostname
|
16
|
+
@parsed_hostname ||= Socket.gethostname.split('.').first
|
17
|
+
end
|
18
|
+
|
19
|
+
def msg2str(msg)
|
20
|
+
case msg
|
21
|
+
when ::String
|
22
|
+
msg
|
23
|
+
when ::Exception
|
24
|
+
"#{ msg.message } (#{ msg.class }): " <<
|
25
|
+
(msg.backtrace || []).join(" | ")
|
26
|
+
else
|
27
|
+
msg.inspect
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'hodel_3000_compliant_logger'
|
6
|
+
|
7
|
+
describe Hodel3000CompliantLogger do
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@out = StringIO.new
|
11
|
+
@log = Hodel3000CompliantLogger.new(@out)
|
12
|
+
Socket.stub(:gethostname).and_return('hostname.domain')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should log stuff in a syslog-like format so that Eric Hodel's Rails Analyzer Tools can parse it" do
|
16
|
+
msg = "Yo ho hello there!"
|
17
|
+
@log.info(msg)
|
18
|
+
@out.string.should match(/^\w{3} \d{2} \d{2}:\d{2}:\d{2} hostname rails\[\d+\]: #{msg}\n$/)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should handle an Exception object used as an argument in Logger#error, rather than blow chunks" do
|
22
|
+
@log.error(Exception.new)
|
23
|
+
@out.string.should match(/Exception/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should display a semi-readable stack trace (albiet on one line) when Logger#error(SomeException) was called" do
|
27
|
+
@log.error(toss_runtime_error)
|
28
|
+
@out.string.should match(/.*? \| .*? \| .*? \|/) # pipe separated stack frames
|
29
|
+
@out.string.should match(/\n$/)
|
30
|
+
@out.string.count("\n").should == 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def toss_runtime_error
|
34
|
+
raise "Catastrophic Failure"
|
35
|
+
rescue => e
|
36
|
+
return e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hodel_3000_compliant_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Geoffrey Grosenbach
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-30 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 1.3.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.
|
38
|
+
email: boss@topfunky.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- hodel_3000_compliant_logger.gemspec
|
49
|
+
- lib/hodel_3000_compliant_logger.rb
|
50
|
+
- spec/hodel_3000_compliant_logger_spec.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/topfunky/hodel_3000_compliant_logger
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Alternate logger for Rails that emits syslog-style output. For use with pl_analyze gem.
|
85
|
+
test_files:
|
86
|
+
- spec/hodel_3000_compliant_logger_spec.rb
|