• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Log4j Issue

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Naresh Shaan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Have a look at these:

Log4jRepositorySelector

ScopedLoggingConfig
 
Naresh Shaan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks A Lot!!!
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic