H
harryos
hi,
I tried log4j for logging in my web app which I deployed on tomcat6.I
wanted to replace all the System.out.println() statements in my
servlets and jsps which I previously used to track the control flow.
I created log4j.properties to write to mylog.log in my application
directory
------------
log4j.rootLogger=DEBUG,myLogFile
log4j.appender.myLogFile=org.apache.log4j.RollingFileAppender
log4j.appender.myLogFile.File=mylog.log
log4j.appender.myLogFile.MaxFileSize=100KB
log4j.appender.myLogFile.MaxBackupIndex=2
log4j.appender.myLogFile.layout=org.apache.log4j.PatternLayout
--------------
and used the Logger instance in my servlet code as below
-------------------------------------------------------------
public class PostBean extends HttpServlet {
....
private Logger log;
public PostBean(){
log=Logger.getLogger("newwebapplog");
}
public void setUrl(String url){
if (url != null && !(url.equals(""))){
this.url=url;
log.debug("url set as :"+url);
}
}
....
}
I am getting these debug() statements printed to mylog.log file.
eg:
Dec 15, 2008 12:21:52 PM: DEBUG [http-8080-1] url set as
This is exactly what I wanted.
But a lot of other info is also being printed into it
eg:
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Java version: 1.6.0_05
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Java vendor: Sun
Microsystems Inc.
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Java class path: E:\Java
\jdk1.6.0_05\lib\tools.jar;E:\tomcat\apache-tomcat-6.0.18\bin
\bootstrap.jar
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Operating system name:
Windows XP
....
How can I tell the logger to log only those statements I give inside
the servlet code?
thanks
harry
I tried log4j for logging in my web app which I deployed on tomcat6.I
wanted to replace all the System.out.println() statements in my
servlets and jsps which I previously used to track the control flow.
I created log4j.properties to write to mylog.log in my application
directory
------------
log4j.rootLogger=DEBUG,myLogFile
log4j.appender.myLogFile=org.apache.log4j.RollingFileAppender
log4j.appender.myLogFile.File=mylog.log
log4j.appender.myLogFile.MaxFileSize=100KB
log4j.appender.myLogFile.MaxBackupIndex=2
log4j.appender.myLogFile.layout=org.apache.log4j.PatternLayout
--------------
and used the Logger instance in my servlet code as below
-------------------------------------------------------------
public class PostBean extends HttpServlet {
....
private Logger log;
public PostBean(){
log=Logger.getLogger("newwebapplog");
}
public void setUrl(String url){
if (url != null && !(url.equals(""))){
this.url=url;
log.debug("url set as :"+url);
}
}
....
}
I am getting these debug() statements printed to mylog.log file.
eg:
Dec 15, 2008 12:21:52 PM: DEBUG [http-8080-1] url set as
This is exactly what I wanted.
But a lot of other info is also being printed into it
eg:
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Java version: 1.6.0_05
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Java vendor: Sun
Microsystems Inc.
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Java class path: E:\Java
\jdk1.6.0_05\lib\tools.jar;E:\tomcat\apache-tomcat-6.0.18\bin
\bootstrap.jar
Dec 15, 2008 12:21:53 PM: DEBUG [http-8080-1] Operating system name:
Windows XP
....
How can I tell the logger to log only those statements I give inside
the servlet code?
thanks
harry