Class: PushyLogger
- Inherits:
-
Logger
- Object
- Logger
- PushyLogger
- Defined in:
- lib/pushyd/pushy_logger.rb
Instance Method Summary collapse
- #add(level, message, lines = {}) ⇒ Object
-
#initialize(logfile, rotation = nil) ⇒ PushyLogger
constructor
A new instance of PushyLogger.
Constructor Details
#initialize(logfile, rotation = nil) ⇒ PushyLogger
Returns a new instance of PushyLogger.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pushyd/pushy_logger.rb', line 5 def initialize logfile, rotation = nil # Call my parent's initializer super # And the formatter self.formatter = proc do |severity, datetime, progname, | # Build common line prefix prefix = "%s %s\t" % [ datetime.strftime(LOG_FORMAT_TIME), severity ] # If we have a bunch of lines, prefix them and send them together if .is_a? Array .map { |line| prefix + line + LOG_NEWLINE}.join else prefix + .to_s + LOG_NEWLINE end end end |
Instance Method Details
#add(level, message, lines = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pushyd/pushy_logger.rb', line 25 def add level, , lines = {} level ||= Logger::DEBUG if lines.is_a? Hash output = build_from_hash lines elsif lines.is_a? Array output = build_from_array lines else output = [] end # Prepend plain message to output output.unshift .force_encoding(Encoding::UTF_8) # Send all this to logger super level, output end |