mirror of
https://github.com/meineerde/rackstash.git
synced 2026-04-03 05:31:37 +00:00
Allow to customize the final newline character when writing to an adapter
This commit is contained in:
parent
a3733923e7
commit
7713bdfdb6
@ -126,16 +126,19 @@ module Rackstash
|
|||||||
private
|
private
|
||||||
|
|
||||||
# Helper method to ensure that a log line passed to {#write} is either a
|
# Helper method to ensure that a log line passed to {#write} is either a
|
||||||
# String that ends in a newline character or is completely empty.
|
# String that ends in a separator character (`"\n"` by default) or is an
|
||||||
|
# empty String.
|
||||||
#
|
#
|
||||||
# @param line [#to_s] a log line
|
# @param line [#to_s] a log line
|
||||||
# @return [String] `line` with a trailing newline character (`"\n"`)
|
# @param sep [String] a separator character which is added to the end of
|
||||||
# appended if necessary
|
# the `line` if not already present there
|
||||||
def normalize_line(line)
|
# @return [String] `line` with the separator character appended if
|
||||||
|
# necessary
|
||||||
|
def normalize_line(line, sep = "\n".freeze)
|
||||||
line = line.to_s
|
line = line.to_s
|
||||||
return line if line.empty? || line.end_with?("\n".freeze)
|
return line if line.empty? || line.end_with?(sep)
|
||||||
|
|
||||||
"#{line}\n"
|
line + sep
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user