How to remove unnecessary logs from log4j2 log's file - java

I want to remove the unnecessary log's that are generated automatically by log4j when i run my suite, I only want the log's which i wrote in the code, please help.
As you can see my actual log's starts from Launched flipcart.com and end with Closed the current window
Also check the log4j2.xml file.

See second answer in How to exclude a single Class from a Log4j Logger / Appender?
Replace
<logger name="com.example.FifthClass">
<level value="FATAL"/>
</logger>
with e.g.
<logger name="io.netty">
<level value="FATAL"/>
</logger>

Related

Google LoggingAppender and stdout

For debugging/testing purposes, I would like Google's Logback LoggingAppender to write to STDOUT instead to connect to Google's Logging API. According to https://github.com/googleapis/java-logging-logback, this should be possible by using redirectToStdout.
My logback.xml:
<appender name="CONSOLE" class="com.google.cloud.logging.logback.LoggingAppender">
<redirectToStdout>true</redirectToStdout>
</appender>
<root>
<level value="info" />
<appender-ref ref="CONSOLE" />
</root>
However, I get an error that no project was set. The error message:
14:48:36,515 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [com.google.cloud.logging.logback.LoggingAppender]
14:48:36,534 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
14:48:36,970 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter#28:16 - RuntimeException in Action for tag [appender] java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the builder.
at java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the builder.
at at com.google.common.base.Preconditions.checkArgument(Preconditions.java:142)
...
Although that should not be necessary according to the documentation cited above, I also tried setting logDestinationProjectId. Note, that doesn't make sense in my case, as I want to run this configuration on my local machine for debug/test purposes. Also, that produced a different error (although that should be ignored according to the documentation).
Any hints what I am missing? Is my use case even supported? If not, how do you test a configuration change for your LoggingAppender before deploying it to Google Cloud?
The linked github issue was accepted and confirmed by a contributor. You can work around by setting an arbitrary project ID, i.e. by setting logDestinationProjectId:
<appender name="CONSOLE" class="com.google.cloud.logging.logback.LoggingAppender">
<redirectToStdout>true</redirectToStdout>
<logDestinationProjectId>TEST</logDestinationProjectId>
</appender>
<root>
<level value="info" />
<appender-ref ref="CONSOLE" />
</root>

log4j.properties file to log4j2.xml conversion

I am upgrading from log4j1.x to log4j-2.8.2
I am trying to convert my existing log4j.properties file to equivalent log4j2.xml.
My first question is can I write log4j2.proeprties file instead of log4j2.xml file?
I found some equivalent tags to log4j.proeprties file in log4j2.xml.
I did not find tags for the below lines. can anybody suggest on this?
# LoggerFactory for ESAPI to utilize Log4J
log4j.loggerFactory=org.owasp.esapi.reference.Log4JLoggerFactory
log4j.category.Default=ALL, CONSOLE, RollingFile2, edelivery
log4j.rootCategory=OFF
log4j.logger.org.apache=INFO
log4j.logger.IntrusionDetector=ERROR
log4j.logger.org.springframework=WARN
Thanks in advance.
What i am sure is:
See the last three lines:
log4j.logger.org.apache=INFO
log4j.logger.IntrusionDetector=ERROR
log4j.logger.org.springframework=WARN
I think in log4j.xml they should be instead of like these below:
<Logger name="org.apache" level="INFO"/>
<Logger name="IntrusionDetector" level="ERROR"/>
<Logger name="org.springframework" level="WARN"/>
And what I am not sure is:
these two lines:
log4j.category.Default=ALL, CONSOLE, RollingFile2, edelivery
log4j.rootCategory=OFF
I guess you have configured some appenders with the name in above line like:
<appender name="CONSOLE">
other proerties....
</appender>
so i think you could try to use these in your log4j.xml:
<root>
<appender-ref ref="ALL" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="RollingFile2" />
<appender-ref ref="edelivery" />
</root>
And What I really don't know is:
log4j.loggerFactory=org.owasp.esapi.reference.Log4JLoggerFactory
I Know nothing about esapi so i could not suggest how to deal with it, hope someone else to give more answer.

JBoss standalone.xml file changes are being overridden

We am using JBoss 7 in our project and have written the logging configuration in standalone.xml file like this,
<subsystem xmlns="urn:jboss:domain:logging:1.0">
.
.
.
<logger category="com.xyz.abc.aspect">
<level name="DEBUG"/>
<handlers>
<handler name="FILE"/>
</handlers>
</logger>
.
.
</subsystem>
Now a situation has arose that i wanted to change the logging configuration by adding use-parent-handlers="false" to avoid the log being redirected to parent handler , now when i add this to standalone.xml
<logger category="com.xyz.abc.aspect" use-parent-handlers="false">
<level name="DEBUG"/>
<handlers>
<handler name="FILE"/>
</handlers>
</logger>
and restart the server the logging configuration is reverted back by JBoss to the previous state i.e
<logger category="com.xyz.abc.aspect">
<level name="DEBUG"/>
<handlers>
<handler name="FILE"/>
</handlers>
</logger>
I have tried deleting standalone_xml_history directory and files under it , but nothing is preventing the overwriting behaviour, can any one please suggest.
I'm not 100% sure, but restarting the server probably causes a write-back action of the config. That means your config gets overwritten by with the "current" config the server knows which is the version before you edited the file.
You could simply use the management console
confguration > core > logging or use the CLI /subsystem=logging/logger=change.me.please:write-attribute(name="use-parent-handlers", value="false") to make those changes.
Alternatively change the config file when the server is stopped.
You need to update standalone.initial.xml in standalone_xml_history directory. Then restart Jboss, your changes would take place.
reference- https://docs.jboss.org/author/display/AS7/Configuration%20file%20history.html

Logging profiles for different environments (Java)

Is there anything in the prod-ready logging world like env-dependent logging profiles. What I mean. Usually one wants different level of detail for different environments.
In action it requires creating multiple log configuration files and when having many environments adding new logger becomes real pain. What I am looking for is:
<logger name="com.google.xyz" additivity="true">
<level value="DEBUG" env="DEV" />
<level value="INFO" env="UAT" />
<level value="ERROR" env="PROD" />
<appender-ref ref="xyz-appender"/>
</logger>
Is such thing exists for some prod-ready Java logging solution?
Logback (an excellent choice for logging with SLF4J) seems to offer this capability in a verbose, but very configurable form.
Conditional processing of configuration files

log4j: logging a package, but excluding its sub-packages

Hi I'd like to exclude certain subpackages from being logged by one of my loggers, as they are being logged by another logger. Eg.
com.mysite.app = logger1
com.mysite.app.news = logger2
com.mysite.app.events = logger3
I'd like logger1 to only log anything with com.mysite.app (including com.mysite.app.utilities) not logged by logger2 and logger3. How could I do that?
(help in properties format please, XML format for other's reference for bonus points)
I always used to think that log4j.logger.com.mysite.app = logger1 takes care of logging messages from subpackages too into logger1.
If you really don't want logger2 and logger3's messages from interfering with those of logger1, you need to set their additivity to false.
log4j.additivity.com.mysite.app.news=false
log4j.additivity.com.mysite.app.events=false
Have a try:
log4j.logger.com.mysite.app=info, stdout
log4j.additivity.com.mysite.app=false
log4j.logger.com.mysite.app.news=off, stdout
log4j.additivity.com.mysite.app.news=false
log4j.logger.com.mysite.app.events=off, stdout
log4j.additivity.com.mysite.app.events=false
For XML configuration:
<logger name="com.mysite.app.news" additivity="false">
<appender-ref ref="logger2" />
</logger>
<logger name="com.mysite.app.events" additivity="false">
<appender-ref ref="logger3" />
</logger>

Categories

Resources