Class: BufferingLogger::SingleLineTransform
- Inherits:
-
Object
- Object
- BufferingLogger::SingleLineTransform
- Defined in:
- lib/buffering_logger/single_line_transform.rb
Overview
This transforms a multiline log into a single line log by replacing newlines with a special string (a single space by default).
This is useful for platforms like Heroku where multiline Rails request logs of one process are interwoven with the request logs of other processes and other log sources (like the Heroku router).
If you want to convert newlines into a special string so that you can later turn them back into newlines (e.g. in Splunk using a [SEDCMD](docs.splunk.com/Documentation/Splunk/latest/admin/Propsconf)) then you can supply a ‘replacement` argument.
Constant Summary collapse
- REPLACEMENT =
' '.freeze
- NEWLINE =
/\r?\n/.freeze
Instance Method Summary collapse
- #call(msg) ⇒ Object
-
#initialize(replacement: REPLACEMENT) ⇒ SingleLineTransform
constructor
A new instance of SingleLineTransform.
Constructor Details
#initialize(replacement: REPLACEMENT) ⇒ SingleLineTransform
Returns a new instance of SingleLineTransform.
17 18 19 |
# File 'lib/buffering_logger/single_line_transform.rb', line 17 def initialize(replacement: REPLACEMENT) @replacement = replacement end |
Instance Method Details
#call(msg) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/buffering_logger/single_line_transform.rb', line 21 def call(msg) msg = msg.dup msg.strip! msg.gsub!(NEWLINE, @replacement) msg << "\n" end |