-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Allow Logstash to write its logs in JSON format #4820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -90,6 +90,10 @@ class LogStash::Runner < Clamp::Command | |||
I18n.t("logstash.web_api.flag.http_port"), | |||
:attribute_name => :web_api_http_port, :default => 9600 | |||
|
|||
option ["--[no-]log-in-json"], :flag, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be consistent, this pr should add the flag according to the current state of master. right now it should use "-", but if it happens to be merged after logstash.yml, then the pr needs to be changed
86e2a41
to
b804686
Compare
Rebased. |
Hand-test that it still works post-rebase:
|
@@ -102,6 +102,10 @@ class LogStash::Runner < Clamp::Command | |||
I18n.t("logstash.runner.flag.allow-env"), | |||
:attribute_name => :allow_env, :default => false | |||
|
|||
option ["--[no-]log-in-json"], :flag, | |||
I18n.t("logstash.agent.flag.log-in-json"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translation missing in yml file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix this. Good catch.
b804686
to
b23393d
Compare
Added tests |
Added help text:
|
ffffac8
to
0335747
Compare
Squashed to a single commit. |
@jordansissel I saw we are targeting this for 5.0 But I am wondering if we should merge it in 2.3.X as an experimental flag? |
@ph I'd be ok merging this into 2.3 and 2.x as a flag that defaults to the old behavior. We can have a new PR later that enables JSON by default in master. Thoughts? |
http://build-eu-00.elastic.co/job/Logstash_PR/2671/testReport/ -- Failing tests seem unrelated to this PR. |
@jordansissel |
@jordansissel Yes the faillure are unrelated. I think its time to make a PR on flores with https://github.com/logstash-plugins/logstash-input-beats/blob/master/spec/support/flores_extensions.rb#L29 ;) |
@ph ok cool. I'll target this for 2.x, 2.4, 5.0, and master |
Merge targets: 2.x, 2.4, 5.0, master |
@jordansissel I found our first serialization errors when running logstash in debug mode.
|
out = File.new("/dev/null", "a") | ||
logger.subscribe(LogStash::Logging::JSON.new(out)) | ||
logger.level = :debug | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will surely fails on windows, we can make it cross platform if we can create a dummy io object that implement the minimal interface to be an IO object but doesn't actually write anything to disk.
OR we can use this, which will make a null stream, I believe it will work on windows but I havent tested it?
File.open(File::NULL, "w")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused, why we need this code and the code in spec_helper
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. this setup_json_logging was an older implementation of what is now in spec_helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it now.
Changes LGTM, small comment concerning the use of |
Regarding the serialization recursing is fine but we should never call
Ultimately we should strive for a whitelist approach to log inclusion IMHO. I wouldn't even mind it if we traversed plain ruby Hash and Array objects, invoking .to_s on everything else. |
Just so people know what JrJackson does do... If it finds an object class not in the above list then it tries to invoke these methods, in order, on the object: Why def to_json
JSON.dump(some_structure)
end This will suspend the JrJackson session, call the JSON library, and return a string for JrJackson to append. |
1fc388c
to
b7399f8
Compare
LGTM @jordansissel |
This is made available by a new `--log-in-json` flag. Default is false. When false, the old behavior [1] is used. When true, JSON logs are emitted. [1] The old behavior is realy two things. First, using Object#inspect to serialize. Second, to color the output if the IO is a tty. Fixes #1569
Use an internal subscriber to verify that JSON output is valid JSON. The purpose is to catch any json serialization errors that would occur while logging. Also had to update a few logger calls to log values that could be serialized (Class instances and similar, at this time, fail to serialize to JSON).
b7399f8
to
619f1eb
Compare
This is made available by a new `--log-in-json` flag. Default is false. When false, the old behavior [1] is used. When true, JSON logs are emitted. [1] The old behavior is realy two things. First, using Object#inspect to serialize. Second, to color the output if the IO is a tty. Fixes #1569 Fixes #4820
Use an internal subscriber to verify that JSON output is valid JSON. The purpose is to catch any json serialization errors that would occur while logging. Also had to update a few logger calls to log values that could be serialized (Class instances and similar, at this time, fail to serialize to JSON). Fixes #4820
Use an internal subscriber to verify that JSON output is valid JSON. The purpose is to catch any json serialization errors that would occur while logging. Also had to update a few logger calls to log values that could be serialized (Class instances and similar, at this time, fail to serialize to JSON). Fixes #4820
I need to backport this PR by hand to 2.x for 2.4. Will open a separate PR for it. |
This is made available by a --log-in-json flag. Default is false. When false, the old behavior [1] is used. When true, JSON logs are emitted. [1] The old behavior is realy two things. First, using Object#inspect to serialize. Second, to color the output if the IO is a tty. For #1569 This is a manual backport of PR #4820 into the 2.x branch.
This is made available by a --log-in-json flag. Default is false. When false, the old behavior [1] is used. When true, JSON logs are emitted. [1] The old behavior is realy two things. First, using Object#inspect to serialize. Second, to color the output if the IO is a tty. For #1569 This is a manual backport of PR #4820 into the 2.x branch. Fixes #5277
Backport to 2.4 done in #5277. |
Will Logstash 2.4 be released any time soon? |
@joshuaspence yes, target is to release it in Aug. |
This is made available by a
--log-in-json
flag. Default is false.When false, the old behavior [1] is used.
When true, JSON logs are emitted.
[1] The old behavior is realy two things. First, using Object#inspect to
serialize. Second, to color the output if the IO is a tty.
For #1569