Class: Lumberjack::Formatter::TruncateFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::TruncateFormatter
- Defined in:
- lib/lumberjack/formatter/truncate_formatter.rb
Overview
Truncate a string object to a specific length. This is useful for formatting messages when there is a limit on the number of characters that can be logged per message. This formatter should only be used when necessary since it is a lossy formatter.
When a string is truncated, it will have a unicode ellipsis character (U+2026) appended to the end of the string.
Instance Method Summary collapse
- #call(obj) ⇒ Object
-
#initialize(length = 32768) ⇒ TruncateFormatter
constructor
A new instance of TruncateFormatter.
Constructor Details
#initialize(length = 32768) ⇒ TruncateFormatter
Returns a new instance of TruncateFormatter.
14 15 16 |
# File 'lib/lumberjack/formatter/truncate_formatter.rb', line 14 def initialize(length = 32768) @length = length end |
Instance Method Details
#call(obj) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/lumberjack/formatter/truncate_formatter.rb', line 18 def call(obj) if obj.is_a?(String) && obj.length > @length "#{obj[0, @length - 1]}…" else obj end end |