Class: Console::JavaUtilLogger::RubyFormatter
- Inherits:
-
Formatter
- Object
- Formatter
- Console::JavaUtilLogger::RubyFormatter
- Defined in:
- lib/color_console/java_util_logger.rb
Overview
Extends java.util.logging.Formatter, adding the ability to customise the log format at runtime, and defaulting to a simpler single-line format more suitable for output to the console.
Constant Summary collapse
- DEFAULT_FORMAT =
'%4$-6s %5$s%n'
Instance Attribute Summary collapse
-
#format_string ⇒ Object
A format string to use when formatting a log record.
Instance Method Summary collapse
-
#format(log_record) ⇒ Object
Format a log record and return a string for publishing by a log handler.
-
#initialize(format = DEFAULT_FORMAT) ⇒ RubyFormatter
constructor
Constructs a new formatter for formatting log records according to a format string.
Constructor Details
#initialize(format = DEFAULT_FORMAT) ⇒ RubyFormatter
Constructs a new formatter for formatting log records according to a format string.
71 72 73 74 |
# File 'lib/color_console/java_util_logger.rb', line 71 def initialize(format = DEFAULT_FORMAT) super() @format_string = format end |
Instance Attribute Details
#format_string ⇒ Object
A format string to use when formatting a log record.
63 64 65 |
# File 'lib/color_console/java_util_logger.rb', line 63 def format_string @format_string end |
Instance Method Details
#format(log_record) ⇒ Object
Format a log record and return a string for publishing by a log handler.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/color_console/java_util_logger.rb', line 78 def format(log_record) lvl = case log_record.level when JavaUtilLogger::Level::WARNING then 'WARN' when JavaUtilLogger::Level::SEVERE then 'ERROR' when JavaUtilLogger::Level::FINEST then 'DEBUG' else log_record.level end java.lang.String.format(@format_string, log_record.millis, log_record.logger_name, log_record.logger_name, lvl, log_record., log_record.thrown) end |