Spring Boot console logs not coming - spring-boot

I am using spring boot and in the logs (console), nothing is coming up except for spring boot ascii art logo. I have slf4j in the classpath pulled by a dependency.

Try adding spring-boot-starter-logging to your POM file instead of slf4j.

I was facing the same issue, when I putted the logs config in external configuration file, then I used it that way:
#PropertySource(value = {"file:${EXTERNAL_PROPERTIES_FILE}"})
Now It's working after moving the log configuration to application.properties in src/main/resources/

Related

Not found neither logback.xml nor log4j.properties in spring boot app

I would like to implement MDC in my microservice. To do the configuration changes, I am unable to find the logback.xml or log4j.properties in my spring boot app resources folder
,
Could any one one help me here , How the logging may implemented here?
The file should be available from your src/resources (put it right next to application.properties).

Spring cloud config server not honoring logging.file property and not logging external file

I'm using spring-boot-starter 2.3.3.RELEASE version. I'm running my spring cloud configuration server in native profile (looking for configuration files in file system). I added
logging.file = /var/log/config.log in application.properties file. But my application is not logging logs to this file.(All other microservices are logging to this location). Am I missing any additional settings for Spring cloud config server? Thank you so much for your help.
In the spring boot 2.3.3 RELEASE documentation the logging properties that specify where the location should be is indicated using the property:
logging.file.path={path}
The documentation:
https://docs.spring.io/spring-boot/docs/2.3.3.RELEASE/reference/htmlsingle/#boot-features-logging-file-output
This modification from logging.path to logging.file.path appears as a deprecation in Spring Boot 2.2:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes#deprecations-in-spring-boot-22
One way to do it with spring-boot application is, setting it from command line argument as default it will dump every thing on console.
logging.file=logs/test.log
Old school but far effective, save path in application.properties
logging.file=logs/test.log

Spring Log4j2 xml file location

using Spring 2.0.5 with Log4j2
Have found works as expected if I place the file log4j2.xml in the resources folder.
However, have found the log4j2 option of monitorInterval="60" to be super useful as if some production issue can increase logging on some class without a restart. However if log4j2.xml is embedded in the jar of course it cannot be modified. so far the best I have been able to do is use 2 copies of log4j2.xml one in the resources and the other in the folder running the jar from.
I can then run:
java -Dlog4j.configurationFile=log4j2.xml -jar myapp.jar
it seems to work the same if started from the maven spring-boot plugin or from Eclipse.
Have tried a number of things such as setting the classpath, the absolute file name etc. but no luck
My question is how can I remove the log4j2.xml file from the resources folder and only specify it on the command line when starting spring?
I am not entirely clear on your question but I can provide the following information which I hope addresses it:
Log4j 2.12.0 added support for Spring Cloud Config and enhanced the support for Spring Boot. As of that version you can include a file named log4j2.system.properties and place any system properties you want defined there. They will be set before Log4j initializes. So you can specify the full URL to the configuration there if you want instead of the command line. You can also add the definition to a file named log4j2.component.properties.
The support for Spring Cloud Config allows you to place the configuration in your Spring Cloud Config server. See Spring CLoud Config support for more details.
Spring Boot initializes logging at least 3 times. The first is usually because the SpringApplication class declares a Logger so logging is initialized before anything else happens. The configuration for that will use "normal" log4j 2 initialization. After that Spring influences how logging initialization occurs primarily because Spring Boot sets the class path to include the jars inside BOOT-INF/lib directory inside your Spring Boot jar.
By using one of the configuration options I outlined above you can move the logging configuration outside of your application and you should not require a logging configuration in the resources directory. In fact, if you look at the sample Spring Cloud Config Application in Log4j you will see it does not include a configuration file in it.

Spring Boot - logging configuration from JBoss

I'd like to know if there is a way to configure Spring Boot logging using JBoss standalone.xml or domain.xml configuration. For now I ended up with two empty files log4j.properties and log4j-file.properties under org\springframework\boot\logging\log4j package in mvn resources in WAR file and it looks like now my logging configuration in domain.xml works because I've overriden default spring-boot log4j configuration.
But there must be a better way to do this instead of this stupid hack. Keep in mind that I don't want to provide external log4j properties file and set it for one of the property in application.properties but I want to use jboss logging system configuration.
EDIT
Strange thing but when I updated Spring Boot to version 1.4.0 then JBoss intercepts the logs and log them only to the file and I don't have logs on the stdout anymore even without custom log4j configuration.

spring restful web service logging

I implemented Spring RESTful Web Service using this tutorial: https://spring.io/guides/gs/rest-service/. I added dependencies for log4j in pom.xml and log4j.properties file in src/main/resources folder. Now I expect logging to be done into log file as stated inthe log4j.properties file instead of to STDOUT. However, logging goes only to STDOUT. How can I fix tis to print log messages to log file?
By default Spring Boot uses LogBack as logging framework.
If you want to configure Log4J, follow this configuration.
You need to exclude Spring Boot's logging module (containing LogBack dependency) and include Spring boot started for log4j.
BTW, log4j is ancient technology, consider moving to logback or log4j2

Resources