Best way to concatenate/collapse stacktraces in logs - spring-boot

My goal is to include my stacktrace and log message into a single log message for my Spring Boot applications. The problem I'm running into is each line of the stacktrace is a separate log message. I want to be able to search my logs for a log level of ERROR and find the log message with the stacktrace. I've found two solutions but not sure which to use.
I can use Logback to put them all in one line but would like to keep the new lines for a pretty format. Also the guide I found might override defaults that I want to keep. https://fabianlee.org/2018/03/09/java-collapsing-multiline-stack-traces-into-a-single-log-event-using-spring-backed-by-logback-or-log4j2/
I could also use ECS and concatenate it there, but it could affect other logs (though I think we only have Java apps). https://docs.aws.amazon.com/AmazonECS/latest/developerguide/firelens-concatanate-multiline.html
Which would be the best way to do it? Also is there a better way to do it in Spring compared to the guide that I found?

Related

Springboot Logging Pattern For Rolling Logs

I am using Springboot version 2.7 and trying to configure the log pattern to be daily rolling.
I am currently using just the application properties file to configure the logging as that's the preference.
I added the following line in the properties file but does not seem to work
logging.logback.rollingpolicy.file-name-pattern=myservice-%d{yyyy-MM-dd}.log
Any clues what I may be missing?
Also, is there a way to check daily log rolling without having to wait for EOD :)
First, you have to specify the file name:
logging.file.name=myservice.log
then you can use the rolling file name pattern
logging.logback.rollingpolicy.file-name-pattern=myservice-%d{yyyy-MM-dd}.log
To force the file change you could set the size to something small
logging.logback.rollingpolicy.max-file-size=100K
To specify the directory you must set this property
logging.file.path=/var/logs
The documentation can be found here:
https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.logging

Logging for Talend job running within spring-boot

We have talend-jobs triggered within Spring-boot application. Is there any way to configure the output of talend-jobs to the application log files?
One workaround we find is to write logs directly to an external file (filePath passed as context-param). But wanted to find if there is a better way to configure this seamlessly.
Not sure if I understood the question correctly, but I guess your concerns might be on what might have happened to the triggered Jobs.
Logging
With Respect to Logging for Talend, You could configure using Log4j,
https://help.talend.com/reader/5DC~TBhDsBie5JTXyVLW4g/QSGCZJKXo~uhKvZDq1DxUg
Monitoring
Regarding the Status of the Job Executed, you could get the execution details retrieved using REST Call(Talend Metaservlet API).
getTaskExecutionStatus
https://help.talend.com/reader/oYf9gKhmYrkWCiSua4qLeg/SLiAyHyDTjuznLR_F~MiQQ
By Modifying the Existing Talend Job,You could also design a like a feedback loop, ie Trigger a REST Call back to your application. With the details of Execution from Talend Job.

Logging for two different environment logs in to a single log file

I am quite new for log4j2 logger and my requirement to write a log from application server and web server.
I am having two different environment on which J BOSS server is deployed.
Now I am having a log file on web server environment which is writing logs for errors and I want to write logs from application server also in same file.
Please suggest.
If you want the logs to be integrated together you should use a solution like Splunk or Elastic Search/Logstash/Kibana (ELK).
When you try to write to a file from 2 different processes your file will get corrupted unless you use file locking. However, your throughput will decrease significantly and it isn't supported for rolling files. So the best approach is to send the logs to a single process where they can be aggregated.

Capture my Go application logs into fluentd

Currently I have a go web application containing over 50 .go files. Each file writes logs on STDOUT for now.
I want to use fluentd to capture these logs and then send them to elasticsearch/kibana.
I search on internet for solution to this. There is one package https://github.com/fluent/fluent-logger-golang .
To use this I would need to change my whole logging related code in each go file.
And there would be many data structures that I would need to Post to fluentd.
Shortly speaking I dont want to use this approach.
Please let me know if there are any other ways to do this.
Thank you
Ideally (at least in my opinion), you would essentially just pipe stdout to Fluentd.
If you happen to be also using Docker for your application you can do this easily using the built in logging drivers:
https://docs.docker.com/engine/admin/logging/overview/
Otherwise, there seem to be a few options to help get stdout to Fluentd:
12Factor App: Capturing stdout/stderr logs with Fluentd

Change trace file in H2

My application uses H2 but already has a log file (ex: abc.log)
Now, I'm trying to make even the H2 to write logs/errors to that file (abc.log) so if something goes wrong an user has only 1 file to send to me (not abc.log AND abc.db.trace file)
Is there a way to achieve that?
You can configure H2 to use SL4FJ as follows:
jdbc:h2:~/test;TRACE_LEVEL_FILE=4
The logger name is h2database.
Ok the solution was to simple for me to believe it but the only thing I had to do is to add
slf4j-api-1.7.2.jar
and
slf4j-jdk14-1.7.2.jar
in my app's classpath.
As SLF4J will (first search and then) discover by itself what underlying logging framework to use it is simply a matter of placing the right implementation.
One warning, it seems that SLF4J can not use more than one frameworks at a time so this solution work ONLY if you have a single existing framework.

Resources