Skip to content
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

How to change the encoder #260

Closed
nicorbes opened this issue Nov 21, 2019 · 10 comments
Closed

How to change the encoder #260

nicorbes opened this issue Nov 21, 2019 · 10 comments

Comments

@nicorbes
Copy link

Hi guys, I wonder how could I use the net.logstash.logback.encoder.LogstashEncoder encoder on your logback.xml configuration file...

How to include the classes into the tomcat-juli.jar?

Thanks in advance!

@hazendaz
Copy link
Member

hazendaz commented Nov 21, 2019

It seems to me that encoder is more for usage when writing the logs that would expect a format like json. This library is internal to tomcats current usage and would not make use of the logging. I'm not sure what value that would bring here. Although I'm open to more discussion on this. A possible PR and/or overview of how this would be beneficial, would be a big help.

Adding link here to logstash encoder

@nicorbes
Copy link
Author

nicorbes commented Nov 21, 2019

Thanks for the quick answer... I couldn't solved this yesterday but I have it running now, nothing like giving some extra time to the ideas.

A little of context... we are migrating our platform to MSA and all new components are made with Spring Boot. But we still have our monolith that is deployed on tomcat 8.5.47. My first reaction, and that is way I run into your project, was to convert our monolith logging (even tomcat logging) to logback and have the same logging that SB is using.

The whole solution is deployed over K8s. And now we are pushing it a little further, consolidating all the pod's logs on ELK.

In order to do that we prefer to have a pre-parsed log in JSON format instead of the plain ones created by Pattern Layout. It is easy that way to send it to logstash directly, avoiding all the RegEx parsing...

Do you know a different approach for this?

@hazendaz
Copy link
Member

That makes perfect sense. Since the logstash encoder is currently written to support using logback directly, I think it would require building out a separate copy of the logstash module that uses the tomcat-slf4j-logback library (just import differences). That could be accomplished in similar way using maven to do the work without additional coding. Part of what is going on with this library and tomcat in general is to avoid conflicts if different libraries are later used for logging. So the extras like jackson probably wouldn't hurt anything by simply being in the tomcat/lib. I'm not sure how much work that would be but I do think it's possible to build such support.

@nicorbes
Copy link
Author

I couldn't make it with the libraries on the lib folder... but it works perfectly fine following the same approach you use for logback jars... I just include the encoder and json libraries in the tomcat-juli ;)

Thanks!

@alin-simionoiuDE
Copy link

sorry, how exactly have you made this work @nicorbes ?

tomcat-juli in question has the following structure (unless i'm looking at the wrong file?)...never mind the versions there

 bin/
 conf/
 src/
 lib/
 LICENSE                 
 LICENSE-logback.txt     
 LICENSE-slf4j.txt       
 LICENSE-tomcat.txt      
 bin/setenv.bat          
 bin/setenv.sh           
 conf/logback-access.xml  
 conf/logback.xml        
 conf/server.xml         
 bin/tomcat-juli.jar     
 src/tomcat-juli-sources.jar  
 lib/logback-core-1.3.0-alpha5.jar  
 lib/logback-access-1.3.0-alpha5.jar  

so you just added logstash-logback-encoder and logback-jackson jars to the lib folder and package back? doesn't seem right..i'm missing something

@alin-simionoiuDE
Copy link

ooo...i figure it out. so the pom file in the parent project needs to be changed a bit to include the encoder and json libraries.

any chance you can another module project for logstash @hazendaz ?

@hazendaz
Copy link
Member

hazendaz commented Dec 14, 2019 via email

@rohitpas
Copy link

@AlinS / @nicorbes I was able to add logback json encoder and related dependencies in tomcat-juli.jar (#20) and I can see tomcat console logs published in Elk stack(Kibana). But I want to send the application logs to elk. Application is bundled as war file and deployed in tomcat.
What needs to be configured in $CATALINA_HOME/conf/logback.xml to get the application logs
or do I need separate logback.xml in application war file?
FYI application is using old log4j for loggings and logs are generated in local files.

@hazendaz
Copy link
Member

There are really 3 spots for configuration.

  • bin/conf with tomcat-juli is separate entirely as tomcat uses different imports so it does not conflict at all.
  • lib that would affect the entire application and all wars (you can add logback.xml there and the jars which will affect all wars)
  • webapps so it only individually affects

If running tomcat with single application, the lib is where you want to place things to ensure all is using slf4j/logback. If underlying wars are using other loggers though you would need to strip those out to pull that off.

@hazendaz
Copy link
Member

hazendaz commented Jun 3, 2024

closing old ticket as logstash is documented now and included in releases.

@hazendaz hazendaz closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants