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.


ryna_sAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.