Class: Eymiha::EasyLogFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Eymiha::EasyLogFormatter
- Defined in:
- lib/eymiha/util/easylog.rb
Overview
EasyLogFormatter instances are used to format logging messages generated by the EasyLogger class. They consist of a date-time stamp, the severity and a log message.
Instance Method Summary collapse
-
#call(severity, time, progname, msg) ⇒ Object
Returns a String containing a formatted log entry consisting of the given date-time stamp, severity and log message.
-
#format_datetime(time) ⇒ Object
Returns a String containing a date-time stamp for the given time in month/day/year hour:minute:second.microsecond format with the microsecond part having the precision specified when the instance was created.
-
#initialize(subsecond_precision = nil) ⇒ EasyLogFormatter
constructor
Creates an instance, using the specified subsecond precision to format fractional seconds.
Constructor Details
#initialize(subsecond_precision = nil) ⇒ EasyLogFormatter
Creates an instance, using the specified subsecond precision to format fractional seconds. If nil, the calculated subsecond precision of the Time class is used.
15 16 17 18 19 20 |
# File 'lib/eymiha/util/easylog.rb', line 15 def initialize(subsecond_precision = nil) super() @AppLogFormat = "%s %-5s %s\n" self.datetime_format = "%m/%d/%y %H:%M:%S." @usecs = subsecond_precision || Time.subsecond_precision end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
Returns a String containing a formatted log entry consisting of the given date-time stamp, severity and log message.
31 32 33 34 35 |
# File 'lib/eymiha/util/easylog.rb', line 31 def call(severity, time, progname, msg) (msg == "") ? "\n" : (@AppLogFormat % [format_datetime(time), severity, msg2str(msg)]) end |
#format_datetime(time) ⇒ Object
Returns a String containing a date-time stamp for the given time in month/day/year hour:minute:second.microsecond format with the microsecond part having the precision specified when the instance was created.
25 26 27 |
# File 'lib/eymiha/util/easylog.rb', line 25 def format_datetime(time) time.strftime(datetime_format) << ("%06d" % time.usec)[0,@usecs] end |