I have following XML configration i would like to convert to java property file.
I am getting below error
log4j:WARN Failed to set property [filter] to value "org.apache.log4j.varia.DenyAllFilter". log4j:ERROR Could not instantiate class [true]. java.lang.ClassNotFoundException: true at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.apache.log4j.helpers.Loader.loadClass(Loader.java:198) at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:326) at org.apache.log4j.PropertyConfigurator.parseAppenderFilters(PropertyConfigurator.java:881) at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:812) at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735) at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615) at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502) at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:395) at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:403) at simpandfile.main(simpandfile.java:10)
My XML configration
<filter class="org.apache.log4j.varia.StringMatchFilter"> <param name="StringToMatch" value="FileNotfound" /> <param name="AcceptOnMatch" value="true" /> </filter> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMin" value="ERROR"/> <param name="LevelMax" value="FATAL"/> </filter> <filter class="org.apache.log4j.varia.DenyAllFilter"/>
After converting the property file is as below. With XML configration it is working fine.
Property File
log4j.rootLogger=INFO, MAIL log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender # here's where I specify the layout and the pattern log4j.appender.MAIL.BufferSize=1 log4j.appender.MAIL.SMTPHost=xxx.example.com [email protected] [email protected] log4j.appender.MAIL.Subject=Test Email. log4j.appender.MAIL.threshold=error log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout log4j.appender.MAIL.layout.ConversionPattern=[%d{ISO8601}]%n%n%-5p%n%n%c%n%n%m%n%n log4j.appender.MAIL.filter=org.apache.log4j.varia.StringMatchFilter log4j.appender.MAIL.filter.StringToMatch=Filenotfound log4j.appender.MAIL.filter.AcceptOnMatch=true log4j.appender.MAIL.filter=org.apache.log4j.varia.DenyAllFilter log4j.logger.com.devdaily.myapp=DEBUG log4j.logger.org.springframework=DEBUG
Please let me know how i can use StringToMatch in property file and specify
The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file.
The log4j. properties file is a log4j configuration file which stores properties in key-value pairs. The log4j properties file contains the entire runtime configuration used by log4j. This file will contain log4j appenders information, log level information and output file names for file appenders.
By default, Log4J 2 looks for a properties file with the name log4j2. properties in the classpath. In a Spring Boot application, the log4j2. properties file will typically be in the resources folder.
println() over Log4j, of course for testing purposes, because it doesn't require any configuration, you can just use it, without bothering about XML or properties file configuration, but the most programmer will agree that they would prefer to use Log4j over println statements, even for test programs if it's easy to ...
log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d %-6p [%c] %m%n log4j.appender.console.filter.1=org.apache.log4j.varia.StringMatchFilter log4j.appender.console.filter.1.StringToMatch=entered log4j.appender.console.filter.1.AcceptOnMatch=true log4j.appender.console.filter.2=org.apache.log4j.varia.DenyAllFilter
does work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With