Permalink
Browse files

ST: Added prettier inspections

  • Loading branch information...
rudionrails committed Oct 11, 2012
1 parent 0b901ac commit c58b864b74c68793a2b571c332a949cfa5118ce9
Showing with 76 additions and 2 deletions.
  1. +18 −0 lib/yell/adapters/base.rb
  2. +5 −0 lib/yell/adapters/datefile.rb
  3. +5 −0 lib/yell/adapters/io.rb
  4. +15 −2 lib/yell/formatter.rb
  5. +16 −0 lib/yell/level.rb
  6. +17 −0 lib/yell/logger.rb
View
@@ -162,6 +162,17 @@ def close
close!
end
+ # Get a pretty string representation of the adapter, including
+ # the inspectable attributes.
+ #
+ # @example Inspect the formatter.
+ # adapter.inspect
+ #
+ # @return [String] The inspection string.
+ def inspect
+ inspection = inspectables.inject( [] ) { |r, c| r << "#{c}: #{send(c).inspect}" }
+ "#<#{self.class.name} #{inspection * ', '}>"
+ end
private
@@ -209,6 +220,13 @@ def write?( event )
@level.nil? || @level.at?( event.level )
end
+ # Get an array of inspected attributes for the adapter.
+ #
+ # @return [ String ] An array of pretty printed field values.
+ def inspectables
+ [ :level ]
+ end
+
end
end
@@ -174,6 +174,11 @@ def header_from( file )
end
end
+ # @override
+ def inspectables
+ super.concat [:date_pattern, :header, :keep, :symlink ]
+ end
+
end
register( :datefile, Yell::Adapters::Datefile )
View
@@ -87,6 +87,11 @@ def stream
synchronize { open! if @stream.nil?; @stream }
end
+ # @override
+ def inspectables
+ super.concat [:format, :colors, :sync]
+ end
+
end
end
View
@@ -85,11 +85,21 @@ def format=( pattern )
# message formatting.
def initialize( pattern = nil, date_pattern = nil )
@pattern = pattern || Yell::DefaultFormat
- @date_pattern = date_pattern
+ @date_pattern = date_pattern || :iso8601
define!
end
+ # Get a pretty string representation of the formatter, including
+ # the pattern and date pattern.
+ #
+ # @example Inspect the formatter.
+ # formatter.inspect
+ #
+ # @return [String] The inspection string.
+ def inspect
+ "#<#{self.class.name} pattern: #{@pattern.inspect}, date_pattern: #{@date_pattern.inspect}>"
+ end
private
@@ -121,7 +131,10 @@ def level( l )
end
def date( t )
- @date_pattern ? t.strftime( @date_pattern ) : t.iso8601
+ case @date_pattern
+ when String then t.strftime( @date_pattern )
+ else t.iso8601
+ end
end
def message( *messages )
View
@@ -138,6 +138,22 @@ def to_i
end
alias :to_int :to_i
+ # Get a pretty string representation of the level, including the
+ # severities.
+ #
+ # @example Inspect the level.
+ # level.inspect
+ #
+ # @return [String] The inspection string.
+ def inspect
+ severities = Yell::Severities.each.with_index.inject( [] ) do |r, (l, i)|
+ r << l if @severities[i]
+ r
+ end
+
+ "#<#{self.class.name} severities: #{severities * ', '}>"
+ end
+
private
View
@@ -124,6 +124,16 @@ def #{name}( *m, &b ) # def info( *m, &b )
EOS
end
+ # Get a pretty string representation of the logger.
+ #
+ # @example Inspect the logger
+ # logger.inspect
+ #
+ # @return [String] The inspection string.
+ def inspect
+ inspection = inspectables.inject( [] ) { |r, c| r << "#{c}: #{send(c).inspect}" }
+ "#<#{self.class.name} #{inspection * ', '}, adapters: #{@adapters.map(&:inspect) * ', '}>"
+ end
private
@@ -149,6 +159,13 @@ def write( event )
@adapters.each { |a| a.write(event) }
end
+ # Get an array of inspected attributes for the adapter.
+ #
+ # @return [ String ] An array of pretty printed field values.
+ def inspectables
+ [ :name, :level ]
+ end
+
end
end

0 comments on commit c58b864

Please sign in to comment.