log4j file appender do not normal - java

My log4j.properties is:
log4j.appender.R.File=../logs/xrzgather.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=100
I have many tomcat server run the application,and all of them run normal with the right log but one of them do not normal,it generate the log file:
xrzgather.log 182M
xrzgather.log.19 254M
xrzgather.log.45 48.6M
xrzgather.log.50 400M
xrzgather.log.90 20.8M
xrzgather.log.92 66.3M
xrzgather.log.99 11.9M
Has anyone know what's wrong?

I find the reason..
I config a Context element in %tomcat_home%\conf\Server.xml like this:
<Context path="xrz-gather" docBase="xrz-gather-web-1.0-SNAPSHOT" />
if I remove this,log will be normal.

Related

How to set JsonTemplateLayout eventTemplateUri outside of classpath in Log4j2

In Log4j2's JsonTemplateLayout, I have no problem using eventTemplateUri: "classpath:LayoutTemplate.jsson" with json file located in rc/main/resources.
However, I would need to keep this file outside of class path. so I would like to use file location something like he way we add log fileName: c:\...
But it's throwing an error when I use eventTemplateUri: "C:\ ....\LayoutTemplate.json"
rror message is " Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLa
yout for element JsonTemplateLayout: java.lang.RuntimeException: failed reading URI: C:...
Did I miss anything here?
is it possible to place this json file outside of class path?
Thanks!
All *Uri configuration knobs in JsonTemplateLayout expect a URI string. In your case, the URI scheme is missing. The eventTemplateUri should look like file:///C:/path/to/LayoutTemplate.json in your case. For internals, see how o.a.l.l.l.template.json.util.Uris.readUri(String,Charset) is implemented.

Deeplearning4j Disable Logging

I have a deeplearning for java project which is producing huge amounts of logger output on STDO. I want to disable that but I cant seem to figure out how to do it.
I have a log4j.properties file in my src/main/resources folder which looks like this:
log4j.rootLogger=ERROR, Console
log4j.logger.play=WARN
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n
log4j.appender.org.springframework=WARN
log4j.appender.org.nd4j=WARN
log4j.appender.org.canova=WARN
log4j.appender.org.datavec=WARN
log4j.appender.org.deeplearning4j=WARN
log4j.appender.opennlp.uima=OFF
log4j.appender.org.apache.uima=OFF
log4j.appender.org.cleartk=OFF
log4j.logger.org.springframework=WARN
log4j.logger.org.nd4j=WARN
log4j.logger.org.canova=WARN
log4j.logger.org.datavec=WARN
log4j.logger.org.deeplearning4j=WARN
log4j.logger.opennlp.uima.util=OFF
log4j.logger.org.apache.uima=OFF
log4j.logger.org.cleartk=OFF
log4j.logger.org.deeplearning4j.optimize.solvers.BaseOptimizer=OFF
slf4j.logger.org.deeplearning4j.optimize.solvers.BaseOptimizer=OFF
The specific output that is far too much is:
21:26:34.860 [main] DEBUG o.d.optimize.solvers.BaseOptimizer - Hit termination condition on iteration 0: score=1.2894165074915344E19, oldScore=1.2894191699433697E19, condition=org.deeplearning4j.optimize.terminations.EpsTermination#55f111f3
which happens multiple times a second while training.
The output of the log entry that you have provided look very much as the SLF4J output with Logback format (not LOG4J output).
Also dependencies of deeplearning4j-core advice SLF4J is used for logging.
Hence your log4j.properties have no effect on deeplearning4j logging. Try to add logback.xml configuration to the resources as well and switch to WARN or ERROR level for root logger, see https://logback.qos.ch/manual/configuration.html
There are some properties in the framework DL4J (1.0.0-beta7) that activate/deactivate the logs. I found some of them:
import org.nd4j.common.config.ND4JSystemProperties;
System.setProperty(ND4JSystemProperties.LOG_INITIALIZATION, "false");
System.setProperty(ND4JSystemProperties.ND4J_IGNORE_AVX, "true");
System.setProperty(ND4JSystemProperties.VERSION_CHECK_PROPERTY, "false");
Notice that this is an unconventional solution. On the other hand, there are some messages impossible to avoid:
MultiLayerNetwork.init()
In this method you can find a OneTimeLogger without validations:
OneTimeLogger.info(log, "Starting MultiLayerNetwork with WorkspaceModes set to [training: {}; inference: {}], cacheMode set to [{}]",
layerWiseConfigurations.getTrainingWorkspaceMode(),
layerWiseConfigurations.getInferenceWorkspaceMode(),
layerWiseConfigurations.getCacheMode());
If you find a better way to disable log messages inside DL4J please share it. There are some other ways outside the DL4J library.

How to add machine name to logfile name using log4j?

Is there a way to add machine name to logfile name in log4j?
This is my situation: I have 4 machines/servers running Weblogic and each machine/server is running 2 instances/nodes of the JVM application (provided by a vendor); this application generates logs using log4j; however logfile names are all the same for all machines/servers and that causes me too much trouble when I have to review or gather logs for troubleshooting.
I've been already able to distinguish instances/nodes among them by using the following - weblogic.Name property:
<appender name="DFe" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="servers/${weblogic.Name}/logs/dfe_${weblogic.Name}.log"/>
Now I need to distinguish logfile names by machine/server name as well. How to do that? Is there any weblogic.Machine property or something?
Example: my machine/server name is "ausplsynapp03" and instance/node names are "track60800-01" and "track60800-02"; so my logfile names would be "dfe_ausplsynapp03_track60800-01.log" and "dfe_ausplsynapp03_track60800-02.log".
Thanks in advance for any help.
By specifying ${weblogic.Name} in your file name or appender pattern you are actually using value from WebLogic JVM argument.
If you can add custom argument to JMV arguments you can use it for logging purposes.
Otherwise you can check for other WebLogic arguments here: https://docs.oracle.com/cd/E13222_01/wls/docs90/admin_ref/weblogicServer.html
Maybe weblogic.Domain will work for you.
If you are OK with having host in log message you can set MDC/NDC attribute and output it to log message using x or %X{key} (reference https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html)
Try to set environment property like below
System.setProperty(“serverHostName“, InetAddress.getLocalHost().getHostName());
then use it in your log4j.xml
as below
param name=”file” value=”${serverHostName}.log”

Where could I find the log configuration file in Weblogic server?

We could modify this file to change the log generation way. For example, We
could change the log rolling way, by hour or by day; and show different log types: info,error and etc.
Thanks.
You could find a file named as config.xml.
It has an item to config log.
Like:
<log>
<file-name>logs/examplesServer.log</file-name>
<rotation-type>byTime</rotation-type>
<number-of-files-limited>true</number-of-files-limited>
<file-time-span>24</file-time-span>
<rotation-time>00:00</rotation-time>
<rotate-log-on-startup>true</rotate-log-on-startup>
<logger-severity>Info</logger-severity>
<log-file-severity>Debug</log-file-severity>
<stdout-severity>Notice</stdout-severity>
<domain-log-broadcast-severity>Notice</domain-log-broadcast-severity>
<memory-buffer-severity>Trace</memory-buffer-severity>
<log4j-logging-enabled>false</log4j-logging-enabled>
<redirect-stdout-to-server-log-enabled>false</redirect-stdout-to-server-log-enabled>
<domain-log-broadcaster-buffer-size>1</domain-log-broadcaster-buffer-size>
</log>
Thanks,
Joseph

log4j in grails : how to log into file?

I have this log4j configuration in my grails config.groovy
log4j = {
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages' // GSP
warn 'org.mortbay.log'
appenders {
rollingFile name:'infoLog', file:'info.log', threshold: org.apache.log4j.Level.INFO, maxFileSize:1024
rollingFile name:'warnLog', file:'warn.log', threshold: org.apache.log4j.Level.WARN, maxFileSize:1024
rollingFile name:'errorLog', file:'error.log', threshold: org.apache.log4j.Level.ERROR, maxFileSize:1024
rollingFile name:'custom', file:'custom.log', maxFileSize:1024
}
root {
info 'infoLog','warnLog','errorLog','custom', stdout
error()
additivity = true
}
}
the infoLog,warnLog and errorLog was from the previous question ... they were working well.
now I add new RollingFile wit name "custom" ...
I tried to log from my controller and service using log.info("something .... ${obj}");
but it seems that message was not inserted into custom.log, do I need to add something to the configuration ?
thank you !!
just got answer from the grails' mailing list:
i just need to add
debug "grails.app"
bellow warn "org.mortbay.log"
case closed ! :)
I have exact the same jetty/tomcat env's. Spent hours to figure it out. The trick is to define the file location (a relative path in my case) as a global variable inside Config.groovy, customized it in the environment blocks, and use the variable location inside log4j closure. Sample code is at: http://denistek.blogspot.com/2010/02/grails-environment-specific-logging-to.html
please see Log4j: How to write to a specific appender?
After all the solution is to put the additivity setting to the package configuration:
info specialLog:'activityLog', additivity:false

Categories

Resources