Strange behavior with log4j2 configuration - spring

I am working with spring cloud and log4j2 with "all" as level.
I will describe two situations with the same config file, I want to write on a Syslog TCP.
First test: I puth my log4j2 config file in resources folder, then, I start my app and start logging to the syslog.
But I need my configuration on a git, so I expose it to an url.
So here comes the second test:
I changed my bootstrap.yml and and the followind line:
logging: config:
http://xxx.xx.xx.75:3000/admin123/config-repository/raw/master/log4j2.xml
Then, I started my app and it starts to write the logging lines of spring boot in my syslog, but, when I put:
LOGGER.info("printing lalala");
Nothing is writed in the syslog and I can see a [FIN, ACK] beetween client and server on my TCP connections.
So, I understand that the config file is readed from the repository, becouse I can see it in my connections capture and becouse the app starts to log on syslog some lines, but something happend after that to close connection and write no more.
I can`t understand what is happening.

You must add the path of the logging.config on the application.yml not the bootstrap.yml and it works.

Related

enable ssl logs in spring boot application from applicaiton.properties

I wanted to print the SSL handshake debug log, this can be achieved easily by using jvm argument -Djavax.net.debug=ssl:handshake:verbose.
My scenario, need to enable the ssl debug logs on a third-party springboot application image. Is it possible to use the jvm arguments in application.properties to print the SSL debug level log?
I don't have the option to update the Dockerfile to use java -Djavax.net.debug=ssl:handshake:verbose applicaiton.jar .....
I'm not sure you can do exactly that with application.properties but you should be able to get close by adding this:
logging.level.javax.net=TRACE
Have a look at this to see how to set logging levels in application.properties

Spring cloud config server on refresh -> logback config also refresh automatically

I can't find any existing article/documentation related to this. The spring cloud config server and logback XML configuration are working in harmony, whenever I change something in my git repo config and trigger refresh of my application, somehow the logback automatically gets updated even though the logback is not in the config server but in the jar file itself.
Basically, my configuration is something like this:
I have an SMTP appender in my logback XML, at startup I'm checking if the enableSMTP is enabled, then I only set the recipient.
<if condition='property("smtpEnabled").equals("true")'>
<then>
<to>to#to.com</to>
</then>
</if>
This is to prevent email sending if the property is disabled, then I'm setting it back programmatically, ideally in EnvironmentChangeEvent. However, changing the property in the config server and calling the /monitor endpoint from the spring cloud config server to push an event to the cloud bus automatically sets this value in logback without programmatically setting it through the event handler.
Is this behavior of environment change and auto reconfigure of logback expected? (note that logback scan is disabled)

Want to read gateway properties from config server

I have a spring cloud gateway in my project and I want to use config server with that.
What exactly I want to do is
enter image description here
I want to read these highlighted values from config server.
i kept these values in config server, still it reads the values from application property not from config,,,, Can som1 plz help here
when i use #value to read these values then it takes config server values...
Is it like config server only works with #value????

Spring boot microservices doesn't work with Intelij IDEA

I am creating a spring boot microservice project with intelij IDEA.
Currently I have developed three seperate spring boot rest services as customer service, vehicle service and spring cloud config server. Spring cloud config server is pointing to a github repository.
The issue is sometimes above projects take more than 10 minutes to run and sometimes does't run and give an error message as "failed to check application readystate intellij attached provider for the vm is not found". I have no idea why this happens ?
There are two possible causes:
1. IntelliJ IDEA and the Spring application are running in different JVMs.
There is a bug for IntelliJ IDEA regarding that:
https://youtrack.jetbrains.com/issue/IDEA-210665
Here is short summary:
IntelliJ IDEA uses local JMX connector for retrieving Spring Boot actuator endpoint's data by default. However, it could be impossible to get local JMX connector address via attach api if Spring Boot application and IntelliJ IDEA are run by different JVMs. In this case, add the following lines to VM options of your Spring Boot run configuration:
-Dcom.sun.management.jmxremote.port={some_port}
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
As mentioned in the official Oracle documentation, this configuration is insecure. Any remote user who knows (or guesses) your port number and host name will be able to monitor and control your Java applications and platform.
2. Prolonged time to retrieve local hostname
You can check that time using inetTester. Normally it should take only several milliseconds to complete. If it takes a long time then you can add the hostname returned by inetTester to /etc/hosts file like this:
127.0.0.1 localhost winsky
::1 localhost winsky

Integration of fluentd with Java application

I am working on integrating spring boot application with fluentd.
When I use FluentdLogger in the application and source as forward in fluentd config file, I am able to log the entries to log file .
So How to provide log level to log statments in spring boot application, default is every statement is printed to file with tag.
Do I have to use in_tail with logging frameworks which will log to file and fluentd will tail from that file to another file.
OR there is way or appender in logback or logging frameworks in java.

Resources