spring boot use log4j2 and log4j2.xml not in resource - spring-boot

I use spring-boot and log4j2, how can my application not read log4j2.xml in resource folder. Read my custom location for the log4j2.xml file?

Related

How to get data for a particular log4j2 property from an alternative source (application.properties)

Having a standard configuration for log4j2 and spring property-file on classpath application.property.
log4j2.xml
<Properties>
...
<Property name="APP_LOG_ROOT">${bundle:application:log.root.dir}</Property>
...
</Properties>
application.properties
...
log.root.dir=/opt/tomcat/logs
...
The data is read into the log4j2.xml correctly, but what if I want to get an alternative property when creating an artifact with maven and put diferent application.property:
mvn clean install -Dapplication.properties.path=file:/some_path/application.properties
?
After that, I can correctly read the new properties.
#Value("${log.root.dir}")
private String ololo;
but the log4j2 cannot do this on its own.
If you want to use any value from Spring's Environment in a Log4j2 configuration file, you need to use the Spring Boot Lookup.
After adding log4j-spring-boot to your classpath, you just need to replace
${bundle:application:log.root.dir}
with
${spring:log.root.dir}

External log4j2.xml file path in application.properties

I am using log4j2 in my project and I have externalized the application.properties and log4j2.xml and I want to provide log4j2.xml file path in application.properties
log4j2.xml and application.properties are in the config folder in the same dir as a jar.
Here is my dependancy
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Directory Structure :
/tmp/myproj/conf/application.properties
/tmp/myproj/conf/log4j2.xml
/tmp/myproj/my.jar
Any help would be appreciated.
Spring Boot expects the log4j2-spring.xml configuration file to be on the classpath. However, you can store it in a different location and point to it using the logging.config property in application.properties.
Try providing below configuration to you application.properties. Here log4j2-spring.xml is on project classpath. If not then try giving your full path as (suppose) "C:/tmp/myproj/conf/log4j2.xml".
**logging.config=classpath:log4j2-spring.xml**
logging.level.org.springframework.web=INFO
logging.file=logs/spring-boot-logging.log
The configuaration in bold should work for you.
Then you need to configure your log4j2-spring.xml as per your requirement.
(simple and also for appenders, see here https://howtodoinjava.com/log4j2/log4j-2-xml-configuration-example/ ).
Note: I have used log4j2-spring.xml in place of you log4j2.xml. you can replace at your will.

Unable to write the logs to the console and log file using spring boot 1.5.3

I am using the Spring boot 1.5.3 release and for logs, I am using the default spring boot logging.
I didn't add any extra dependencies for this and added the below properties to my application.properties file.
logging.level.org.springframework.web=info
logging.level.com.mypackage.service.*=debug
logging.level.root=info
logging.pattern.console=%d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger.%M - %msg%n"
But the spring logs are writing to the console and application logs are not writing to the console and "System.out.println" also not printing in the console while deploying the application in tomcat.
Kindly provide me how to resolve this issue and print system out statements.
Wildcard is not needed there, this will be sufficient
logging.level.com.mypackage.service=debug
Remember that if you have your root on info level, then no debug logs will come whatsoever, so debug logs from com.mypackage.service will be suppressed.
Try to include the starter loggin dependency. It's included by default in all the spring starters projects but I cannot see your pom so I'm not sure about your pom configuration.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>

Spring boot logging with log4.properties file in not working

I have log4j.properties file under resources folder. Now I am passing logging.file=/Users/jkuriakos/web/rnt/dr/rnt.log in application.properties file.
How can I use the log4j.properties file to load all information (like smtp server etc) from log4j.properties file?
Exclude the spring-boot-starter-logging from your pom file and add following dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
This should make spring boot pick up log4j.properties from resources folder.
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging

Jboss EAP 6.1 spring modules class loading not working

I have a spring integration project deployed in jboss as a WAR file.
The project uses maven and structured to support any type of archival War or Jar.
However, the dependencies of the project (all spring jars and custom jars) should be externalized
The reason would be that, later there would be 100s of Spring Integration flows would be deployed and if we have the jars in WEB-INF/libs the size of WAR grows to ~ 50MB. As we have abstracted much of our functionality in a seperate jar (would be added as dependency to my spring integration project), Externalization will result in reducing the WAR file to ~ 5 KB.
I do not have a web.xml and use the WebInitializer for loading the context (Which is part of my common functionality and added as dependency)
Below is what I have tried with JBOSS.
Created a module com.xxx.yyy and added all my spring/third party and custom jars as resources.
Added the dependency to manifest file. (This did not work)
Added the jboss-deployment-structure.xml to my war WEB-INF (did not work)
If I give the wrong module name its throws errors as module
not found.
The war gets deployed, but not initialized. If I have the dependencies in my WEB-INF/lib, everything works as expected.
Below is the jboss deployment structure xml that I used.
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<dependencies>
<module name="com.xxx.yyy" services="import" >
<imports>
<include path="META-INF**"/>
<include path="org**"/>
</imports>
</module>
</dependencies>
</deployment>
</jboss-deployment-structure>
Here is the expectation,
Externalize the Jar dependencies.
Import the dependencies to my war(manifest or jboss-deployment-structure.xml)
Should be used Spring Service should be initialize.
The deployed war should be working as it does if the libraries are
in WEB-INF
Please help...
With JBOSS EAP 6, Its not possible to deploy the war without a web.xml, But such is possible only with tomcat or by using spring boot.
Also, to address this problem, we had to create a dummy web.xml and use jboss modules to load dependencies.

Resources