Skip to content

Commit 26aec39

Browse files
committed
Use empty string for no structured data
Signed-off-by: Tero Saarni <[email protected]>
1 parent 622b522 commit 26aec39

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ use priority field if set to false
239239
===== `structured_data`
240240

241241
* Value type is <<string,string>>
242-
* Default value is `nil`
242+
* There is no default value for this setting.
243243

244244
RFC5424 structured data is a string of one or more structured data elements, including brackets.
245245
The elements need to be formatted according to link:https://datatracker.ietf.org/doc/html/rfc5424#section-6.3[RFC5424 section 6.3], for example:

lib/logstash/outputs/syslog.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class LogStash::Outputs::Syslog < LogStash::Outputs::Base
126126
config :rfc, :validate => ["rfc3164", "rfc5424"], :default => "rfc3164"
127127

128128
# RFC5424 structured data.
129-
config :structured_data, :validate => :string, :default => nil
129+
config :structured_data, :validate => :string, :default => ""
130130

131131
def register
132132
@client_socket = nil
@@ -145,7 +145,7 @@ def register
145145
# use instance variable to avoid string comparison for each event
146146
@is_rfc3164 = (@rfc == "rfc3164")
147147

148-
if @is_rfc3164 && !@structured_data.nil?
148+
if @is_rfc3164 && !@structured_data.empty?
149149
raise LogStash::ConfigurationError, "Structured data is not supported for RFC3164"
150150
end
151151

@@ -177,7 +177,7 @@ def publish(event, payload)
177177
syslog_msg = "<#{priority.to_s}>#{timestamp} #{sourcehost} #{appname}[#{procid}]: #{message}"
178178
else
179179
msgid = event.sprintf(@msgid)
180-
sd = @structured_data.nil? ? "-" : event.sprintf(@structured_data)
180+
sd = @structured_data.empty? ? "-" : event.sprintf(@structured_data)
181181
timestamp = event.sprintf("%{+YYYY-MM-dd'T'HH:mm:ss.SSSZZ}")
182182
syslog_msg = "<#{priority.to_s}>1 #{timestamp} #{sourcehost} #{appname} #{procid} #{msgid} #{sd} #{message}"
183183
end

0 commit comments

Comments
 (0)