Permalink
Browse files

ST: Added :progname to Yell::Event and refactored some specs

  • Loading branch information...
1 parent 1548a97 commit f33f7042d99f3a85d25db7807eb796187e3f0bfa @rudionrails committed Oct 4, 2012
Showing with 24 additions and 9 deletions.
  1. +8 −2 lib/yell/event.rb
  2. +1 −0 lib/yell/formatter.rb
  3. +4 −0 spec/yell/event_spec.rb
  4. +11 −7 spec/yell/formatter_spec.rb
View
@@ -18,6 +18,7 @@ class Event
# Prefetch those values (no need to do that on every new instance)
@@hostname = Socket.gethostname rescue nil
@@pid = Process.pid
+ @@progname = $0
# Accessor to the log level
attr_reader :level
@@ -47,16 +48,21 @@ def initialize( level, *messages, &block )
@method = nil
end
- # Accessor to the pid
+ # Accessor to the hostname
def hostname
@@hostname
end
- # Accessor to the hostname
+ # Accessor to the pid
def pid
@@pid
end
+ # Accessor to the progname
+ def progname
+ @@progname
+ end
+
# Accessor to filename the log event occured
def file
_caller! if @file.nil?
View
@@ -67,6 +67,7 @@ def format=( pattern )
"d" => "date(event.time)", # ISO8601 Timestamp
"h" => "event.hostname", # Hostname
"p" => "event.pid", # PID
+ "P" => "event.progname", # Progname
"t" => "event.thread_id", # Thread ID
"F" => "event.file", # Path with filename where the logger was called
"f" => "File.basename(event.file)", # Filename where the loger was called
View
@@ -70,4 +70,8 @@ def self._event( level, message )
it { should == Process.pid }
end
+ context :progname do
+ subject { event.progname }
+ it { should == $0 }
+ end
end
@@ -14,37 +14,41 @@
context "%m" do
subject { "%m" }
- it { format.should == "Hello World!" }
+ it { format.should == event.messages.join(' ') }
end
context "%l" do
subject { "%l" }
- it { format.should == "I" }
+ it { format.should == Yell::Severities[event.level][0,1] }
end
context "%L" do
subject { "%L" }
- it { format.should == "INFO" }
+ it { format.should == Yell::Severities[event.level] }
end
context "%d" do
subject { "%d" }
- it { format.should == time.iso8601 }
+ it { format.should == event.time.iso8601 }
end
context "%p" do
subject { "%p" }
- it { format.should == Process.pid.to_s }
+ it { format.should == event.pid.to_s }
end
+ context "%P" do
+ subject { "%P" }
+ it { format.should == event.progname }
+ end
context "%t" do
subject { "%t" }
- it { format.should == Thread.current.object_id.to_s }
+ it { format.should == event.thread_id.to_s }
end
context "%h" do
subject { "%h" }
- it { format.should == Socket.gethostname }
+ it { format.should == event.hostname }
end
context "caller" do

0 comments on commit f33f704

Please sign in to comment.