I am trying to use Flume Appender Properties of log4j2 .But the following errors are obtained when run the program .
2016-01-20 16:36:42,436 main ERROR Appenders contains an invalid element or attribute "Flume"
2016-01-20 16:36:42,436 main ERROR Appenders contains an invalid element or attribute "Flume"
2016-01-20 16:36:42,446 main ERROR Unable to locate appender "eventLogger" for logger config "root"
2016-01-20 16:36:42,446 main ERROR Unable to locate appender "eventLogger" for logger config "root"
The log4j.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<Flume name="eventLogger" compress="false" type="Avro">
<Agent host="192.168.8.50" port="41414"/>
</Flume>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="eventLogger" />
</Root>
</Loggers>
</Configuration>
And in .java code
LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
File file = new File("src/log4j2.xml");
context.setConfigLocation(file.toURI());
How I can figure out the problem .May be log4j2 doesn't work properly .
I encountered a similar situation, even Appender element is not recognized under Appenders. the fix is to add strict = "true" in configuration, like below
Configuration status="WARN" strict="true"
Do you have the log4j flume jar in your classpath? If you set status to debug you should see more information.
Related
I have a simple question, hope I will get a simple answer.
I need a log4j2 xml which will dump ALL logs no matter where they are generated from. Now, funny thing is that, I see all the logs that I do not want to see, but logs from my file show up the dreaded "log4j:WARN No appenders could be found for logger".
My simple log xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Console Appender -->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<!-- File Appender -->
<File name="File"
fileName="./log/abc.log">
<PatternLayout
pattern="%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" />
</File>
</Appenders>
<category name="com.abc.def.config.AppInitializer">
<priority value="DEBUG" />
<appender-ref ref="File" />
</category>
<category name="com.oli">
<priority value="DEBUG" />
<appender-ref ref="File" />
</category>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console" />
<AppenderRef ref="File" />
</Root>
</Loggers>
Can somebody improve this xml file so that I am able to see the logs generated by my class "com.abc.def.config.AppInitializer" in the log file ?
Note, more logs is not bad for me, but missing logs absolutely not an option .. the ultimate goal is to "filter out messages that we do not need" rather than "filter in messages we need".
The error message log4j:WARN No appenders could be found for logger is not a Log4j2 warning.
It is coming from a log4j-1.2.x jar that is still on the classpath somewhere.
When migrating to Log4j2, include the log4-1.2-api jar and make sure to remove any log4j-1.2.x jars from the classpath.
From the config file you provided this seems quite good. You should see your log messages on the console as well as in the file.
The warning you get at the very beginning already give you a hint - the system is not able to find your configfile. So how did you name it and where did you put it. The way log4j2 is looking for your configuration is the following:
Log4j will inspect the "log4j.configurationFile" system property
and, if set, will attempt to load the configuration using the
ConfigurationFactory that matches the file extension.
If no system
property is set the properties ConfigurationFactory will look for
log4j2-test.properties in the classpath.
If no such file is found
the YAML ConfigurationFactory will look for log4j2-test.yaml or
log4j2-test.yml in the classpath.
If no such file is found the JSON
ConfigurationFactory will look for log4j2-test.json or
log4j2-test.jsn in the classpath.
If no such file is found the XML
ConfigurationFactory will look for log4j2-test.xml in the classpath.
If a test file cannot be located the properties ConfigurationFactory
will look for log4j2.properties on the classpath.
If a properties file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath.
If a YAML file cannot be
located the JSON ConfigurationFactory will look for log4j2.json or
log4j2.jsn on the classpath.
If a JSON file cannot be located the
XML ConfigurationFactory will try to locate log4j2.xml on the
classpath.
If no configuration file could be located the
DefaultConfiguration will be used. This will cause logging output to
go to the console.
This one was stolen from Log4j2 documentation.
Hope that helps. If not feel free to post your code (github link would be nice) so we can check in more depth.
I am trying to start the hazelcast using the default hazelcast.xml and the start script provide by hazelcast. I am setting the logging type to log4j2 in the hazelcast.xml. I am seeing this message in the logs.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.
I couldn't figure out the way to change the default log level. Could anyone help me on how to set the default log level?
This works for me,
export JAVA_OPTS="-Dhazelcast.logging.type=log4j2 -Dlog4j.configurationFile=./log4j2.xml"
And then have a file named log4j2.xml in the current folder containing
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="ConsoleRed" target="SYSTEM_OUT">
<PatternLayout pattern="%red{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}"/>
</Console>
<Console name="ConsoleWhite" target="SYSTEM_OUT">
<PatternLayout pattern="%white{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}"/>
</Console>
<Console name="ConsoleYellow" target="SYSTEM_OUT">
<PatternLayout pattern="%yellow{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.hazelcast" level="info" additivity="false">
<AppenderRef ref="ConsoleYellow"/>
</Logger>
<Logger name="com.hazelcast.core" level="info" additivity="false">
<AppenderRef ref="ConsoleRed"/>
</Logger>
<Root level="error">
<AppenderRef ref="ConsoleWhite"/>
</Root>
</Loggers>
</Configuration>
If you have colours on, you'll see different colours for the different types of messages.
Error report says:
2016-06-17 09:37:14,122 main ERROR Error processing element Appender ([Appenders: null]): CLASS_NOT_FOUND
2016-06-17 09:37:14,168 main ERROR Unable to locate appender "Console" for logger config "root"
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Appender type="File" name="Console" fileName="C:\Users\raghi\Documents\NetBeansProjects\mdepth\JavaApplication3\build\classes\oo.txt">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Appender>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
<Root level="info">
<appender-ref ref="Console"/>
</Root>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
It looks like we can't append this way to the log file. There is something wrong here. Please help me out on this instead of any downvotes.
You are using a mix of the strict syntax and non-strict syntax. You also have 3 root loggers but you can only have one. Please review http://logging.apache.org/log4j/2.x/manual/configuration.html
I have a simple XML format log4j config file. I am trying to incorporate ESAPI log4j requirement of adding their factory.
How do I reconcile this format (I am guessing strict XML format) to simple XML format that I am using below. If I just add this line in, ESAPI just dies with the exception:
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.spi.LoggerFactory
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
I have added logging in my project but i have two issues.First is that new lines are not coming between various log enteries. And second is that I am not able to change the log location to relative path also. Here is my log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<File name="A1" fileName="C:\log\A1.log" append="false">
<PatternLayout pattern="%t %-5p %c{2} - %m%n"/>
</File>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.log4j.xml" level="debug">
<AppenderRef ref="A1"/>
</Logger>
<Root level="debug">
<AppenderRef ref="A1"/>
</Root>
</Loggers>
</Configuration>
Your configuration looks correct: the pattern for both appenders ends in %n, which should make every message appear on separate lines. If you want an empty line between two log entries, you can try using a pattern that ends in %n%n.
If your output looks like all messages are concatenated without newlines, like this:
main INFO my.class - message1main INFO my.class - message2main INFO my.class - message3
Then it is most likely that your application is actually using a different configuration than the one shown in your question. Could it be that one of your jars contains an old log4j2.xml config file?