In my web application I am inititalizing logging in my web application by using the PropertyConfigurator.configure(filepath) function in a servlet which is loaded on startup.
String log4jfile = getInitParameter("log4j-init-file");
if (log4jfile != null) {
String propfile = getServletContext().getRealPath(log4jfile);
PropertyConfigurator.configure(propfile);
I have placed my log4j.properties file in WEB_INF/classes directory and am specifying the file as
log4j.appender.rollingFile.File=${catalina.home}/logs/myapp.log
My root logger was initally configured as:
log4j.rootLogger=DEBUG, rollingFile,console
(I believe the console attribute also logs the statements into catalina.out)
In windows the logging seems to occor normally with the statements appearing in the log file.
In unix my logging statements are being redirected to the catalina.out instead of my actual log file(Which contains only logs from the initalization servlet). All subsequent logs show up in catalina.out.
This leads me to believe that my log4j is not getting set properly but I am unable to figure out the cause. Could anyone help me figure out where the problem might be.
Thanks in advance,
Fell
It may be a permissions problem - check the owners and permissions of the ${catalina.home}/logs directory.
It will depend on the server you are using.
Is it Tomcat? Is it the same version on Windows and on Linux?
Check whether you have set CATALINA_HOME environmental variable in your machine.
You can check it in linux by typing 'echo $CATALINA_HOME'.
Related
I wonder why my spring project with tomcat server got catalina.out file with size 40GB. Any solutions, please.catalina.out reach 40 GB
catalina.out reaches such a large size because:
1- there might be many logging messages sent to console handler, and
2- also there is not any rotation of catalina.out (and no policy to remove older catalina.out).
First, as there might be some duplication and the messages in catalina.out , which could also be stored in *log messages too, I'd check if the contents of the log files (catalina.[DATE].log) are the same as those of catalina.out, if so then you can edit file conf/logging.properties and remove console handler
I'd also check the level of the log messages and set a higher level if possible. Look for this line in conf/logging.properties
java.util.logging.ConsoleHandler.level = ....
Possible levels, in increasing level of frequency are SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST or ALL. I'd try replace ALL, FINEST, FINER, FINE by CONFIG or even INFO. For instance, by setting it to INFO, all SEVERE, WARNING and INFO messages will be logged but not any with a level to the right of that list.
Also another option is set a limit to console handler by adding this line to conf/logging.properties
java.util.logging.ConsoleHandler.limit = 1024000
and rotate catalina.out configuring an automatic task to remove older ones.
if you are linux user to handle this from system is pretty easy you can configure logrotation with logrotate this is very easy
Step : 1 (Create Logrotate file)
root#c2dapp01-usea1e# vim /etc/logrotate.d/tomcat
Step : Add rotation instruction for linux log rotator
/opt/tomcat/latest/logs/catalina.out {
copytruncate
daily
rotate 7
compress
missingok
size 100M
}
Step : 3 Add cron job to run daily in crond.daily or create custom cron (This file is by default there if not then only create)
root#c2dapp01-usea1e:# vim /etc/cron.daily/logrotate
# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
[ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
This script can be run manually.
/usr/sbin/logrotate /etc/logrotate.conf
Most probably the huge size of logs is due to the DEBUG mode setting of log4j. Change this setting to WARN and the size of logging will be reduced.
This is quite common to see catalina.out file expanding.
this could be used to clear the log of catalina.out file without stopping tomcat with the command below.
sudo cat /dev/null > /opt/tomcat/apache-tomcat-9.0.37/logs/catalina.out
To keep catalina.out smaller in size, either one of the following ways can be used:
You could use the above Linux command and add it to a CronScheduler
to run daily/ weekly/ monthly or yearly as preferred.
Use logrotate tool in Linux. It is a log managing command-line tool
in Linux. This can rotate the log files under different conditions.
Particularly, we can rotate log files on a fixed duration or if the
file has grown to a certain size. You can click here for more
info on this.
i have following code i want command line result save in my textfile also how do this. please help
#echo off
set JAVA_HOME=C:\jdk1.5.0_05
set CLI_HOME=c:\projects\utds\applications\cli
set CLI_LIB=%CLI_HOME%\lib
set CLASSPATH=%CLI_LIB%\commons-logging.jar;%CLI_LIB%\commons-logging-api.jar
set CLASSPATH=%CLASSPATH%;%CLI_LIB%\spring.jar;%CLI_LIB%\spring-core.jar;%CLI_LIB%\spring-support.jar;%CLI_LIB%\spring-remoting.jar
set CLASSPATH=%CLASSPATH%;%CLI_LIB%\utds-infra.jar;%CLI_HOME%\src\conf\spring;%CLI_HOME%\src\conf
set CLASSPATH=%CLASSPATH%;%CLI_LIB%\aopalliance.jar
set CLASSPATH=%CLASSPATH%;%CLI_HOME%\dist\cli.jar;%JAVA_HOME%\jre\lib\ext\comm.jar
set path=%JAVA_HOME%\bin;%path%
java -Dport=COM3 -DbaudRate=19200 -Dparser=panasonicCliParser -DappContext=applicationContext-service.xml com.utds.cli.service.comm.CallerIdListener
I would pipe the output of the batch command into a text file by running the following command in the command prompt:
myBatchFile.bat > output.log
Okay it looks like you're trying to put the output of the program into a text file. If that is the case, in your code just add:
java > log.txt
In my opinion, you should better use your logging library. I can see from the script here above that your applications uses Apache's commons-logging and the output shows it is clearly used.
This library is a wrapper indeed. It can use Log4J or JDK's logging library under the hood.
Of course, this requires much more learning and struggling with configuration files but the advantage for you is that you could (following the implementation you chose):
Filter logs following their gravity (debug < info < warning < error...) and/or the classes emitting them. Some libraries are quite verbose .
Create rolling log files : once the the log file reaches a certain size, a new log file can be created and the old one is backup-ed. (It can be possible to limit the number of backups...).
Create a log file per day
Log into databases if you ever need it...
....
add only >mylog.txt Thanks All
java -Dport=COM3 -DbaudRate=19200 -Dparser=panasonicCliParser -DappContext=applicationContext-service.xml com.utds.cli.service.comm.CallerIdListener> mylogs.txt
i am trying run the websphere liberty profile server from the command line. I am following the steps told here : https://developer.ibm.com/wasdev/downloads/liberty-profile-using-non-eclipse-environments/
I have created the server with the name server1.
But when the extraction completes and I try to start the server using the command : server start server1
the server throws an error : CWWKE0054E: Unable to open file C:\wlp\wlp\usr\servers\server1\logs\C:\Users\Furquan\AppData\Local\Temp\\ihp_custom_batches.log.. Now I know this cant be a valid path, but I dont know where and how to change it. Please help !!
This error is related to the LOG_FILE environment variable that you have defined in your environment by some other program. To solve that, you have the following opions:
Remove LOG_FILE env variable, if it is no longer needed by your system
If you cant do that, override it via server.env file, that you can create in the wlp\usr\servers\serverName directory with the following content:
LOG_FILE=console.log
As last resort (this is not recommended, will make your installation NOT SUPPORTED and in certain installations might get overwritten by updates) - modify the server.bat command line script - in the script find the following section:
if not defined LOG_FILE (
set X_LOG_FILE=console.log
) else (
set X_LOG_FILE=!LOG_FILE!
)
And after the line set X_LOG_FILE=!LOG_FILE! just add another line that will override it with the default like this set X_LOG_FILE=console.log
In general, I'd recommend second solution (with the server.env file), as it is the most portable and will work in any environment.
I have the similar problem for IBM Support Assistant V5. After I deleted %LOG_FILE% from Environment Variables, it worked.
On a particular server (Windows 2012 server R2) I am having trouble creating a temp file. I get the following error everytime I try.
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(Unknown Source)
etc..
The error happens everytime the following code is ran:
InputStream inputStream = portalBean.createPDF( sessionID, foCode );
Things I have tried
Changed the java.io.tmpdir variable on the fly. System.setProperty("java.io.tmpdir", "C:\\");
Added -Djava.io.tmpdir=c:\\temp to the webnetwork lax file to an unrestricted location.
I tried setting the webNetwork service to run as a specified user with rights to temp files e.g. the Administrator.
Made sure I have free disk space and I cleaned out the c:\windows\temp folder.
Made sure the tmp environment variables were set to their default values.
I also tried running the service from a command prompt which was opened with the Run As Administrator option.
And the IOException lingers still. I have another server running the same code without issue (Windows Server 2012).
Does anyone else have any Ideas of what else I can try to resolve this issue? And or any tips on how I can debug the issue more thoroughly to get a grasp of what is going on?
One tool you can use to debug this is process monitor from system internal tool kit. The step is: add a filter to only monitor your process (I think it is javaw.exe in your case), after the error happens, go through the file activities in the process monitor log, you can find how the process is finding files and which directories the process searched. If the process is searching in the wrong directory, you can find it from the log.
I just used this tool to figure out a JVM crash problem today.
Based on the description of your problem, I guess the path variable of the process is changed in the middle of your code, with another tool process explore you can view the path variable of the process, it might help.
Try and create instead a directory somewhere under your home directory:
final Path tmpdir = Paths.get(System.getProperty("user.home"), "tmp");
Files.createDirectories(tmpdir);
System.setProperty("java.io.tmpdir", tmpdir.toAbsolutePath().toString());
Then try and Files.createTempFile() in there.
Note that if Files.createDirectories() refers to an existing file which is not a directory, you'll get a FileAlreadyExistsException.
Trying to run my GWT app, I get
EntryPoint initialization exception
Exception while loading module ch.swisstph.mortqual.mqui.client.MqInput. See Development Mode for details.
com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:513)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:385)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:722)
in the web browser, and just
/usr/lib/jvm/java-6-openjdk/bin/java -Xmx256m -Didea.launcher.port=7537 -Didea.launcher.bin.path=/home/dhardy/code/download/idea-IU-129.239/bin -Dfile.encoding=UTF-8 -classpath /home/install/gwt/gwt-dev.jar:/home/dhardy/p/mortqual/mqui/src:/usr/lib/jvm/java-6-openjdk/jre/lib/compilefontconfig.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jsse.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rhino.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jce.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/management-agent.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/javazic.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/resources.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/charsets.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/java-atk-wrapper.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/pulse-java.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/ext/dnsns.jar:/home/dhardy/p/mortqual/mqui/out/test/mqui:/home/dhardy/p/mortqual/mqui/out/production/mqui:/home/install/appengine-java-sdk/lib/shared/jsp-api.jar:/home/install/appengine-java-sdk/lib/shared/appengine-local-runtime-shared.jar:/home/install/appengine-java-sdk/lib/shared/el-api.jar:/home/install/appengine-java-sdk/lib/shared/servlet-api.jar:/home/install/appengine-java-sdk/lib/user/appengine-api-1.0-sdk-1.7.5.jar:/home/install/gwt/gwt-user.jar:/home/dhardy/p/mortqual/anacod/target/test-classes:/home/dhardy/p/mortqual/anacod/target/classes:/home/dhardy/.m2/repository/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12.jar:/home/dhardy/.m2/repository/log4j/log4j/1.2.14/log4j-1.2.14.jar:/home/dhardy/.m2/repository/com/beust/jcommander/1.30/jcommander-1.30.jar:/home/dhardy/.m2/repository/org/apache/poi/poi/3.9-20130311/poi-3.9-20130311.jar:/home/dhardy/.m2/repository/org/apache/poi/poi-ooxml/3.9/poi-ooxml-3.9.jar:/home/dhardy/.m2/repository/org/apache/poi/poi-ooxml-schemas/3.9/poi-ooxml-schemas-3.9.jar:/home/dhardy/.m2/repository/org/apache/xmlbeans/xmlbeans/2.3.0/xmlbeans-2.3.0.jar:/home/dhardy/.m2/repository/stax/stax-api/1.0.1/stax-api-1.0.1.jar:/home/dhardy/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/home/dhardy/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar:/home/install/gwt/validation-api-1.0.0.GA-sources.jar:/home/install/gwt/validation-api-1.0.0.GA.jar:/home/dhardy/code/download/idea-IU-129.239/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain com.google.gwt.dev.DevMode -war /home/dhardy/.IntelliJIdea12/system/gwt/mqui.5589a251/mqui.33ff3210/run/www -remoteUI 7901:IntelliJIdea -startupUrl mqInput.html ch.swisstph.mortqual.mqui.mqui
log4j:WARN No appenders could be found for logger (org.apache.jasper.compiler.JspRuntimeContext).
log4j:WARN Please initialize the log4j system properly.
Dev Mode initialized. Startup URL:
http://127.0.0.1:8888/mqInput.html?gwt.codesvr=127.0.0.1:9997
on the command line. There are no logs I can find (I tried configuring log4j via a .properties file, which removed its warnings but still didn't give me any logs).
So how do I solve this?
The two most likely causes are renaming of my start-up page and pushing some code out to a library.
try putting -logLevel SPAM in your command line arguments, this will print detailed logs, also you can put explicit GWT.log("message") in your entry point code, that will tell your how far it is going (normal logging doesn't work directly with gwt).
This page describes how to debug GWT in general, how ever my suggestion would be run debug this directly in eclipse with gwt plugin, GWT support in eclipse is amazing.