-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Explore use of SLF4J in Logstash and default to Log4j #4548
Comments
❤️ |
I agree, and that would be lovely. However, with some of Logstash being implemented in Java now and in the future, we'd have to maintain a Cabin->Java bridge that maybe isn't great. It might be easier to move to log4j or something similar. SLF4J's MDC isn't as simple as Cabin's structured logging, but I believe we can implement a wrapper for SLF4J (or log4j) that makes contextual logging calls take fewer lines of code. |
+1 on the initiative. This would also potentially provide similarities/consistence with ES in terms of logging configuration? +1 on a thin sugar JRuby wrapper on top of SLF4J |
As an implementation/api detail, I think Cabin's main fault is the required creation of hashes every time you pass context. I think this could be solved by doing a varargs method instead of requiring a map:
The above would (hopefully) not require creation of a hash every time the method is invoked. I haven't done any performance tests to see the impact of this (memory and speed), but wanted to document this idea here. This is especially important for logging from Java because there's no easy "map literal" syntax in Java, iirc. |
as an fyi there is a json formatter for logback (+ slf4j) https://github.com/qos-ch/logback-contrib/tree/master/json wonder if we could provide a varargs Ruby api as @jordansissel mentioned and offer pluggable slf4j logging with preloaded formatters for a) current log format support and b) json output using logback+json ? |
+1 for having log rotation configuration (and defaults) as we do in Elasticsearch! +1 for using |
@suyograo , i recommend using rjack slf4j After all, what we want is an abstraction layer over the Logging Layer. |
I am +1 for logback + cabin features I feel, as we develop more java sections to LS, we are going to have a real problem logging in the same structured way as we do now in Ruby land. I am thinking expressly of @ph rewrite of the beats input internals in Java - how the hell is he going to log structurally from Java? |
@guyboertje, i think Cabin should be abandoned in favour of a Logging Facade in Logstash. I suggest overloading methods to JSON Serialize custom objects or even apply a codec to do it. Imho there should be a bridge between Ruby and Java. Of course the log layout will have to change in order to do this but it will become unified and clean. |
@driverpt - I am suggesting "Cabin like" features in a Java wrapper/facade. |
@guyboertje why not "Ruby Logger" like features ? http://ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html. It's not that hard to do. Only difference is to add alias_method from fatal to error. |
Some brief research into seeing what libraries can support us:
@talevy and I are noodling about what kind of interface we can provide (ignoring the implementation details) and he likes a Builder approach:
I initially tried a simpler model of
However, we lose type checking and other compile-time validation, so that's no good. I like @talevy's builder approach. Still, we need to figure out if any of the existing log libraries even will work for us. To do:
|
More research:
We may be able to move forward with only using |
More research -- log4j2's LogEvent is an Serializable interface , so we could possibly implement our own Logger that emits custom LogEvents that serializes well and forget whatever |
log4j2 is quite the labyrinth, haha. Ok, so, @talevy's idea right now is to ship an Object via log4j2's ObjectEvent, and we provide a custom serializer (to json) via a custom Layout implementation. This would let users choose their preferred Appender strategies, let us deliver JSON logs, and hopefully let us log complex object types (collections, etc). More news soon. |
@jordansissel , why complicate? Baby steps, first iteration do something similar to Logstash-core-event-java.
|
I am not sure what you mean. The main concern is being able to log On Tuesday, May 17, 2016, Luís Duarte notifications@github.com wrote:
|
Thats why you should keep the Strings and just serialize the Ruby Objects in the ruby bridge when calling for example @logger.log(some_hash, some_hash_2) |
I am not sure I am making the problem clear. Structured data logging is not On Tuesday, May 17, 2016, Luís Duarte notifications@github.com wrote:
|
@talevy @jordansissel - Y'all have seen this, https://github.com/logstash/logstash-logback-encoder/tree/master, right? Not proposing to use it - just analysis or inspiration |
@guyboertje indeed, some interesting API reading here: https://github.com/logstash/logstash-logback-encoder/tree/master#loggingevent_fields |
Rough notes from a meeting with @talevy @colinsurprenant @guyboertje and @ph
Use Cabin like interface so we don’t have to update plugins of existing usage Proposal to use Cabin4j: A new wrapper with Cabin like interface written in Java. This can be used in both JRuby and Java land. None of the existing plugins need to change. Reimplement internally use Log4j. Pure Java and JRuby should use the same logger object. Look into using https://github.com/lenny/log4jruby and if the package registration magic is simple enough, we wouldn't need this extra dependency on log4jruby. Support Structured Logging
In theory, the indirection level should look like this:
Next steps:
|
@suyograo , i still believe that you should use SLF4J Facade instead of building your own. It's pretty easy to create Bridges in SLF4J. What i would do is:
See this In my honest and humble opinion, Cabin4J is a nice effort, good solution, but i believe that using SLF4J that is a de-facto standard in the Java World would make it easier to manage the logging. You might even give the opportunity to the Developers to use their own Logging Framework, e.g.: Loggly, Logsene, etcd.... |
Several things about slf4j / log4j2 :
|
@fbaligand thanks for the info! Since we want to allow for more structure than just a
something like this: System.setProperty("Log4jLogEventFactory", CustomLogEventFactory.class.getName()); I wish things like JSONLayout were not |
Closing in favor of #5650 Implementation work is happening there.. |
The current logging library in Logstash is Cabin, created by @jordansissel to primarily overcome the lack of structured logging capabilities in ruby logger. More information on cabin features can be found in its readme.
There are some additional requirements for logging in LS that needs to be addressed:
See Proposal: Allow per plugin log level configuration #2040, Allow finer logging configuration for config compilation, pipeline and plugin system #3692
See Ability to govern log file generated by logstash #3658, Logstash is crashed every day #2520
We could add all these features to Cabin, but most of these requirements are already solved by libraries like log4j2 which can be run on JRuby. Better yet, we can introduce SLF4J which is an abstraction layer over logging libraries and we can ship a default Log4J implementation. SLF4J and Log4J both support structured logging: http://www.slf4j.org/api/org/slf4j/MDC.html so this migration should be easy.
The text was updated successfully, but these errors were encountered: