web project use log4j output log information

1. Set log4j properties file

# For JBoss: Avoid to setup Log4J outside $ JBOSS_HOME/server/default/deploy/log4j.xml!
# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
log4j.rootLogger = INFO, stdout, logfile
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern =% d (yyyy / MM / dd HH: mm: ss: SSS)% p [% c] -% m% n

log4j.appender.logfile = org.apache.log4j.RollingFileAppender
# Log4j.appender.logfile.File = $ (TOMCAT_HOME) / webapps / jtosa / WebRoot / logs / jtosaLog.log
log4j.appender.logfile.File = $ (webapp.root) / WEB-INF/logs/jtosaLog.log
log4j.appender.logfile.MaxFileSize = 512KB
# Keep five backup files.
log4j.appender.logfile.MaxBackupIndex = 3
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout = org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern =% d (yyyy / MM / dd HH: mm: ss: SSS)% p [% c] -% m% n

log4j.category.org.apache.commons.dbcp = INFO
log4j.category.com.ibatis = INFO
log4j.category.org.springframework = INFO
log4j.category.com.jtosa = INFO




2. Config project web.xml

<! - Log4j configure ->
<context-param>
<param-name> log4jConfigLocation </ param-name>
<param-value> WEB-INF/log4j.properties </ param-value>
</ Context-param>
<context-param>
<param-name> log4jRefreshInterval </ param-name>
<param-value> 60000 </ param-value>
</ Context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</ Listener-class>
</ Listener>

3. Test

private Logger logger = Logger.getLogger (EmployeeAction.class);

logger.info ("[User:" + emp.getEmpNumber () + "out of the system]");

4. Look log file info

2010/04/28 01:10:45:031 INFO [com.jtosa.struts.action.EmployeeAction] - [user: test password: test log]
2010/04/28 01:10:47:468 INFO [com.jtosa.struts.action.EmployeeAction] - [User: test Password: test Login failed, reason: user or password is incorrect]
2010/04/28 01:10:53:140 INFO [com.jtosa.struts.action.EmployeeAction] - [user: test password: 123 log]
2010/04/28 01:10:53:156 INFO [com.jtosa.struts.action.EmployeeAction] - [User: test Password: 123 Login successful]
2010/04/28 01:10:59:156 INFO [com.jtosa.struts.action.EmployeeAction] - [user: test out the system]

remark: project use framework (spring + ibatis + struts2 + Extjs)
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of web project use log4j output log information

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • spring struts2.0 hibernate environmental structures .. despair carried out more than one hour only with good.

    http://www.qqread.com/java/2008/06/f413762.html Look here. . Note added myeclipse support spring when necessary add the commons-dbcp database connection pool package. And to add hibernate support. . Finally add struts2 support. . Oh the lazy point. . . fu

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

  • spring struts2.0 hibernate bug killer 1

    exception There is no Action mapped for namespace / and action name checkLogin. - [Unknown location] com.opensymphony.xwork2.DefaultActionProxy.prepare (DefaultActionProxy.java: 186) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries