File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Unable to log to file 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 "Unable to log to file" Watch "Unable to log to file" New topic
Author

Unable to log to file

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 522
    
    2

Hi,

Please find my log4j.xml below. Using this, I'm not able to log my statements to the file. I'm assuming some thing must be wrong in configuration. Could some one point me that to me?



and this file is in my classpath.

I could see below statements in console

log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [com.sample] additivity to [true].
log4j: Level value for com.sample is [DEBUG].
log4j: com.sample level set to DEBUG
log4j: Class name: [org.apache.log4j.RollingFileAppender]
log4j: Setting property [file] to [../log/Sample.log].
log4j: Setting property [append] to [true].
log4j: Setting property [threshold] to [DEBUG].
log4j: Setting property [maxFileSize] to [5000KB].
log4j: Setting property [maxBackupIndex] to [10].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d %5p- %m%n].
log4j: setFile called: ../log/Sample.log, true
log4j: setFile ended
log4j: Adding appender named [Sample] to category [com.sample].


From the above statements, it seems everything has been properly initialized. but still it is failing in logging.


Regards
KumarRaja

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 522
    
    2

Can some body help me on this ?
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Is the log file getting created? It is usually a good idea to include a root category/logger, have you tried that?

What does your logging code look like?
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 522
    
    2

Carol Enderlin wrote:Is the log file getting created? It is usually a good idea to include a root category/logger, have you tried that?

Thanks Carol, after adding root category it started logging. However, I'm confused on the location of the log file.

I placed my log4j.xml in /WEB-INF/classes and have my log file path set to



and have my web app deployed in GlassFish server. The application is deployed under %GLASS_FISH%/domains/domain1/eclipseApps/MyApp and was expecting my log to be under MyApp/Log folder. But it created the log under %GLASS_FISH%/domains/domain1/config. I did not understand this. Any advice.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
In my experience (not with GlassFish), with a relative path the log file will be created relative to the directory the server starts up in. Sounds like log files created with a relative path are created in domainname/config for GlassFish (google search).

There's an interesting blog post, Where are your log4j files? , that gives some options for getting the log file where you want it.

We use WebLogic Server and our log files are created in domainname/log by specifying file as log/appname.log.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

Carol Enderlin wrote:In my experience (not with GlassFish), with a relative path the log file will be created relative to the directory the server starts up in.


And imagining that the server's current working directory will be the WEB-INF directory of one of the applications running in that server (or in fact any directory related to that application)` is quite unrealistic.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 522
    
    2

Thank you all.
 
wood burning stoves
 
subject: Unable to log to file