No configuration file found when using log4j with log4j2 in project? - junit

In our project we are using log4j with log4j2. When I run the Junits I am getting the error saying: No log4j2 configuration file found.
But the log4j.properties file is already available in that location. Using Google I found that it requires logj2.xml file then I provided log4j2.xml file. Junits runs smoothly.
Does log4j2 support property file or not?

Log4j2 does support property file.
Property file can be provided to log4j2 by either of the following 2 ways:
Set the configuration file path (with .properties extension) in "log4j.configurationFile" system property.
Name the configuration file log4j2.properties (or log4j2-test.properties) and keep that in the classpath.
You can learn more about log4j2 configuration here.

Related

Interfering options to reference Logback config file, starting with Micronaut 3.8

As far as I can see, starting with Micronaut 3.8, there has been added another option to configure referenced Logback's
XML config file within application.yml file(s), as described also in current
Micronaut documentation.
This results in sometimes weird logging behaviour!
I've described my observations, details, my course of investigation, and reference to a stripped down Micronaut test
project in
another StackOverflow thread.
To sum it up:
Option to reference custom Logback XML configuration file also within application.yml file
does NOT affect log messages issued before final setup of Micronaut's ApplicationContext, like often the case
with frameworks like OR mappers (even if they get set up in response to configs laid down in application.yml
file itself), and
interferes with option to reference Logback XML config file via JVM CLI switch (like
-Dlogback.configurationFile=logback-json-format.xml). To me it seems that both config options (JVM CLI switch
and application.yml) have to be in sync to gain expected behaviour.
So I propose to
make reference to Logback XML configurations in application.yml files count from "the beginning" (if at all
possible), and
establish a priority between both config options, like "JVM CLI switch supersedes config in application.yml"
in this regard, and/or
make io.micronaut.logging.impl.LogbackLoggingSystem be aware of mentioned JVM CLI switch.
Otherwise I'm not sure if the option to configure custom Logback XML file within application.yml is that valuable in
the light of all the "troubles".

How to copy custom JSON file into docker container?

I added custom json file in my .net core web API project and retrieved data from that json file successfully when running it in debug mode. But, problem arise when I run it as a docker container.
Error says "Missing custom.json file in '/app/' folder".
Please modify your .csproj file like below to include your custom.json file.
<ItemGroup>
<ResolvedFileToPublish Include="azure-functions-host/appsettings.prod.json">
<RelativePath>azure-functions-host/appsettings.prod.json</RelativePath>
</ResolvedFileToPublish>
</ItemGroup>
For more details, you can refer below post.
ASP.NET Core: Exclude or include files on publish

How can I define an arbitrary file outside my web application to configure log4j2

My web application will be deployed to Weblogic application servers on Windows and Linux/Unix in different environments. The log file location, appenders and log levels will vary between the different deployments and we would like to be able to change the logging configuration during runtime (by exchanging the config file), so I cannot embed a log4j2.xml (or whatever other config file) into my deployment. And since I'm running on Application servers I cannot control, I've got no chance to add environment variables to point to another configuration Location.
Currently, my log4j2.xml resides in the classpath of my application and is being packaged into my war file. Is there any way to tell Log4J2 to use a configuration file e. g. relative to the application root (like Log4J's configureAndWatch(fileLocation) method)?
I found lots of examples of how to configure Log4J2, but everything I found about the config file location points to the applications class path.
I finally found a solution for my problem. I added a file named
log4j2.component.properties
to my project (in src/main/resources). This file contains a property pointing to the location of my log4j2 configuration file:
log4j.configurationFile=.//path//on//my//application//server//someLog4j2ConfigFile.xml
This causes log4j2 to read that file and configure itself from it's content.

can not find cas.log for apereo/cas 4

I need to configire an apereo/cas in a few of days.
First I build the cas.war 4.2.2 according to https://github.com/apereo/cas-overlay-template. And then I deployed it in tomcat 8.0.36. After I start up the tomcat, I can login by the sample user(casuser: Mellon), but I can't find the cas.log file in tomcat/logs folder and other place by find / -name cas.log.
I have copied the log4j2.xml to /etc/cas/ as per the reference. Besides, I can't any error in tomcat/logs.
Did some one solve this problem or have a clue?
By the way, the log4j2 xml is available at https://github.com/apereo/cas-overlay-template/blob/master/etc/log4j2.xml.
Your log4j file describes where the log should be found. You'll file the location inside a file appender.
Your logging configuration doesn't specify a path so the files are going to end up in whatever the current directory is when you start tomcat or whatever tomcat sets the working directory to. That probably isn't what you want.

Configuration path of Log4j2

I am trying to adopt Log4j2 to my project. Since my Java Application is packeted in a JAR file. I don't want "log4j2.xml" configuration packaged inside of JAR file. I am trying to learn how configuration file works from "http://logging.apache.org/log4j/2.x/manual/configuration.html"
But seems there is no clear instruction regarding altering the configuration file path of the Log4j2.
After googling about this topic I found something like "Referencing log4j config file within executable JAR" Referencing log4j config file within executable JAR, But this solution is not available any more according to "http://logging.apache.org/log4j/2.x/manual/migration.html" (if I understand it correctly).
So I am wondering if someone have any idea about this issue.
Thanks
You can set the system property to specify the configuration path.
set the
"-Dlog4j.configurationFile="D:\learning\blog\20130115\config\LogConfig.xml"
in VM arguments. replace
"D:\learning\blog\20130115\config\LogConfig.xml"
to your configuration path.
Put the log4j2.xml file in resource directory in your project so that the log4j will locate files under class path automatically.
Loading log4j2.xml file from the customized location-
You can use the System property/ VM arguments- Dlog4j.configurationFile=file:/path/to/file/log4j2.xml
This will work for any web application.
For some legacy applications, you can create a class for loading log4j2.xml/ log4j2.properties from the custom location on the machine like- D:/property/log4j2.xml
Using any of these approach,during application startup, the log4j2.xml file from the src/resources folder will be overridden by the custom location log4j.xml file.
Try using -Dlogging.config=Path_to_your_file