wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes Log4j Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Log4j Issue" Watch "Log4j Issue" New topic
Author

Log4j Issue

Naresh Shaan
Greenhorn

Joined: Mar 18, 2006
Posts: 22
Hi,

i am trying to log my web application. for a trail basis, i have developed a simple application with just one servlet.

i have initialized my logger. i am deploying onto jboss server.

when i deploy my application, i am able to see log's on my jboss server console.

but my log file is not being created.


i have looked at the previous posts on log4j and noticed one common thing. "configuring log4j using .properties file".i am configuring log4j using log4j.xml.
Is configuring with properties file more easier than configuring with an xml??

here are files...

---------------------------------------------------
log4j.xml
---------------------------------------------------

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<!-- Appender Reference for CONSOLE based logging -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p [%c{1}] %m%n" />
</layout>
</appender>

<!-- Appender refernce for FILE based logging -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="D:/Logs/MyWebApplicationLogger.log" />
<param name="Append" value="true" />
<param name="Threshold" value="debug" />
<param name="DatePattern" value="'.'yyyy-mm-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%x] %d{ABSOLUTE} %-5p [%c{1}] %m%n" />
</layout>
</appender>

<logger name="myWebApplicationLogger.MyWebApplicationLoggerServlet" additivity="false">
<level value="INFO"></level>
<appender-ref ref="CONSOLE"></appender-ref>
<appender-ref ref="FILE"></appender-ref>
</logger>

<root>
<level value="INFO" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>

</log4j:configuration>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
---------------------------------------------
MyWebApplicationLoggerServlet.java
---------------------------------------------
package myWebApplicationLogger;

import javax.servlet.http.HttpServlet;

import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class MyWebApplicationLoggerServlet extends HttpServlet {

private static final long serialVersionUID = 1L;
private Logger logger=null;

public MyWebApplicationLoggerServlet() {
// TODO Auto-generated constructor stub
}

public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
logger=Logger.getLogger(MyWebApplicationLoggerServlet.class.getName());
logger.info("Servlet Is Initilized!!!");
}

public void destroy() {
// TODO Auto-generated method stub
logger.info("Servlet Is Destroyed!!!");
}

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
resp.setContentType("text/html");
resp.getWriter().println("Hello World!!!");
logger.info("In doGet() Method!!!");
}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


i have placed my .dtd and .xml file in /WEB-INF/classes

can someone help me out here.

thanks


"The greatest pleasure in life is doing what people say you cannot do." - Walter Bagehot
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10146
    
165

i have initialized my logger. i am deploying onto jboss server.

when i deploy my application, i am able to see log's on my jboss server console.

but my log file is not being created.

i have placed my .dtd and .xml file in /WEB-INF/classes


JBoss wont pick up this log4j.xml file. JBoss comes with its own log4j.xml file under %JBOSS_HOME%/server/default/conf folder. You will have to add your logger configurations to that file. You could have your own log4j.xml file but thats going to require some additional efforts.


[My Blog] [JavaRanch Journal]
Naresh Shaan
Greenhorn

Joined: Mar 18, 2006
Posts: 22
Thank you JaiKiran




You could have your own log4j.xml file but thats going to require some additional efforts.



can you please tell me what those additional efforts are?? it worth trying as we have many application running in our jboss server and we need to have a separate logger for each of these application. i understand the point that its of no use modifying the log4j.xml when the server is running and expect the changes to happen. and we cannot restart the server just because we are deploying a new application into it.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10146
    
165

can you please tell me what those additional efforts are??


Have a look at these:

Log4jRepositorySelector

ScopedLoggingConfig
Naresh Shaan
Greenhorn

Joined: Mar 18, 2006
Posts: 22
Thanks A Lot!!!
 
GeeCON Prague 2014
 
subject: Log4j Issue