• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

Logger in Servlet

I have a Servlet in which I am using log4j.

In my servlet I have written

public class MyServlet extends HttpServlet {

static Logger logger = Logger
                  .getLogger(com.MyServlet.class);

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException    {

       
                  logger.debug(" Logger comment");
   }
}

Inside WEB-INF\properties directory there is log4j.properties file with the following content

log4j.rootCategory=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.FileAppender
log4j.appender.dest1.File=/logger.txt
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

But when this servlet is called I can't find anywhere the logger.txt file.
Please tell me how it'll be created.


0
ryna_s
Asked:
ryna_s
  • 5
  • 3
  • 3
1 Solution
 
kawasCommented:
the properties file belongs in WEB-INF/classes
0
 
kawasCommented:
also, use the full path insteasd of /logger.txt, or the file will end up in the System.getProperty("user.dir") directory
0
 
ryna_sAuthor Commented:
>>also, use the full path insteasd of /logger.txt, or the file will end up in the System.getProperty("user.dir") directory

How to specify the full path. The path needs to be in context of tomcat.
I cannot specify something like C:\logger.txt because I don't know whether user will have a C: directory in his system or not. The logger file should be created somewhere inside the webapp which is deployed in Tomcat
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ryna_sAuthor Commented:
>>the properties file belongs in WEB-INF/classes

Cannot put the properties file in classes, since I'll not be shipping the classes folder to the client. Instead jar file for all the classes will be shipped.
Also, properties file cannot be inside the jar file, as client will have to modify the properties file.
0
 
ryna_sAuthor Commented:
Anyone please
0
 
kawasCommented:
the path could be specified like so:
    ${catalina.home}/webapps/YOUR_APP_NAME
${catalina.home} is set when tomcat starts.

The place for the properties file is the classes folder, sorry about that.
0
 
kawasCommented:
> The place for the properties file is the classes folder
You might want to try emailing the log people and asking them how you can load the file from somewhere else.
0
 
thomas908Commented:
>>  ${catalina.home}/webapps/YOUR_APP_NAME

I have put it insdie classes, but its still not creating the logger file
0
 
kawasCommented:
should have read ${catalina.home}/webapps/YOUR_APP_NAME/log.txt

Is that what you have?
0
 
thomas908Commented:
You an try by giving java home, catalina home does not work on my system
0
 
thomas908Commented:
oops,sorry the answer had already been accepted
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now