How to specify the location of the log file in tomcat (using log4j output log information)

Source: Internet
Author: User
Tags getmessage sql server driver stmt log4j
I used log4j in a struts project and posted it on Tomcat, but when I started Tomcat it was always impossible to specify the location of the log file.

If you specify this, when you start Tomcat, you always say that you cannot find the log file.
Log4j.appender.logfile.file=log/shitingguanai.log

If you specify the following,
Log4j.appender.logfile.file=shitingguanai.log
The log file ran under Tomcat's Bin directory.

Which could explain the reason, or tell me how to assign the log file to the log folder.

Log file is located in Webapps/myapp/log




Log4j.properties files are as follows:

# Set Root category priority to INFO and it only appender to CONSOLE.
Log4j.rootcategory=info, LOGFILE

# LOGFILE is set to be a File appender using a patternlayout.
Log4j.appender.logfile=org.apache.log4j.dailyrollingfileappender
Log4j.appender.logfile.file=shitingguanai.log
Log4j.appender.logfile.threshold=info
Log4j.appender.logfile.layout=org.apache.log4j.patternlayout
Log4j.appender.logfile.layout.conversionpattern=%d{yyyy/mm/dd HH:mm:ss}%m%n

Log4j.logger.cn.dlyg=info

No one knows?

Yes, I also encountered this problem, and finally I wrote directly to the real path ....
Look forward to a better solution .... Thank you

Log4j.appender.LOGFILE.File's path defaults to Tomcat's Bin

If you want to modify to another directory without using an absolute path, use a relative path.

For example, if you want to set the log directory in the Tomcat directory, use the
Og4j.appender.logfile.file=.. /log/shitingguanai.log


I want to output the log to the log directory under my application and set the path as follows:
Log4j.appender.logfile.file=.. /webapps/onlinehome/log/shitingguanai.log

But no, comrade, it still hit the bin directory, but the file name is "." Webappsonlinehomelogshitingguanai.log "

I'm ft ...

And, Log4j.properties's position, is there a rule? Must be placed under SRC.


Thank you for your advice.

Modify the logging configuration file under the Conf folder

############################################################
# Handler specific properties.
# describes specific configuration info for handlers.
############################################################

1catalina.org.apache.juli.filehandler.level = FINE
1catalina.org.apache.juli.filehandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.filehandler.prefix = Catalina.

2localhost.org.apache.juli.filehandler.level = FINE
2localhost.org.apache.juli.filehandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.filehandler.prefix = localhost.

3manager.org.apache.juli.filehandler.level = FINE
3manager.org.apache.juli.filehandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.filehandler.prefix = Manager.

4admin.org.apache.juli.filehandler.level = FINE
4admin.org.apache.juli.filehandler.directory = ${catalina.base}/logs
4admin.org.apache.juli.filehandler.prefix = admin.

5host-manager.org.apache.juli.filehandler.level = FINE
5host-manager.org.apache.juli.filehandler.directory = ${catalina.base}/logs
5host-manager.org.apache.juli.filehandler.prefix = Host-manager.

Java.util.logging.ConsoleHandler.level = FINE
Java.util.logging.ConsoleHandler.formatter = Java.util.logging.SimpleFormatter

Just get rid of all the output directories here, okay?

C:/tomcat 5.0/conf
There is no file called logging under the folder ....

Logging.properties file

Only Catalina.properties and Jk2.properties, no logging.properties.
Do you want to build one yourself?

A roar ...

Not so good ...

Package test;

Import java.sql.*;

public class Test
{
String sdbdriver= "Com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sconnstr= "Jdbc:microsoft:sqlserver://localhost:8080;databasename=bookshop";
String user = "sa";
String password = "123456";
Connection Conn=null;
ResultSet Rs=null;

Public test ()
{
try{
Class.forName (Sdbdriver);
}
catch (Java.lang.ClassNotFoundException e)
{
SYSTEM.ERR.PRINTLN ("Error is: Personbean ():" +e.getmessage ());
}
}


The first page shows all the records, query all the data;
Public ResultSet Executequery_findall ()
{
String sql_findall= "Select Id,title,name,body from Body";
Rs=null;
Try
{
Conn=drivermanager.getconnection (Sconnstr,user,password);
Statement stmt=conn.createstatement ();
Rs=stmt.executequery (Sql_findall);
}

catch (SQLException ex)
{
System.err.println ("Aq.executequery:" +ex.getmessage ());
}
Return RS;
}
}
: Com.microsoft.jdbc.sqlserver.SQLServerDriver
No suitable driver
Both of these were wrong.
I suspect the SQL Server driver is not installed.
But in the JSP can also use

Please help to see the master thank you

Change the configuration file to

Log4j.rootlogger=info, R
Log4j.appender.r=org.apache.log4j.rollingfileappender
Log4j.appender.r.file=d:/tomcat 5.0/logs/log4j.log
log4j.appender.r.maxfilesize=100kb
Log4j.appender.r.maxbackupindex=1
Log4j.appender.r.layout=org.apache.log4j.patternlayout
log4j.appender.r.layout.conversionpattern=%p%t%c-%m%n

Try it.

Try the driver of your SQL Server to the Common/lib directory under Tomcat, if not, add the drive to the Classpath

It's not going to work, it's not even log.

I've tried an absolute path before, and I can't.


Roar ....

.. /webapps/onlinehome/log/shitingguanai.log

I remember I tried this once, it's not good. Today, I tried another day to succeed.

I'm ft.

Anyway, 3Q!!!


There is one more question:
Log4j.properties file location How to specify AH.
Must be placed in the SRC directory.

A roar ...

Web.xml Add the initialization servlet as follows:

Init

Cn.dapei.common.config.InitServlet


Log4j
/web-inf/conf/log4j.properties

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.