wood burning stoves 2.0*
The moose likes Java in General and the fly likes log4j refuses to write to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "log4j refuses to write to file" Watch "log4j refuses to write to file" New topic
Author

log4j refuses to write to file

Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
Hello.

After working in several projects where log4j was in place before i got there, i ended up building a project from scratch that will use log4j. I have as Maven dependency to log4j version 1.2.14. I set up some logging and after reading the online documentation, i ended up copying a log4j.properties file from there. It looks like this:


Now when i run my application (in OC4J) i can see my logging in the console, but the "mylogfile.log" file is never created. I verified that the properties file is indeed the one used by changing the logging layout and checking the results in the console output.

Can anyone out there help me figure out why the appender is not working?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Have you tried using an absolute path and checking that location? Is there anything in the log on startup indicating a configuration error?
Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
David Newton wrote:Have you tried using an absolute path and checking that location? Is there anything in the log on startup indicating a configuration error?


Yes, i tried that too. No log file.

Nothing in any log file indicates any problems with log4j... :confused:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't see anything wrong with it, and the exact same config file (but with an absolute path) works fine for me (although I've wrapped it with Commons Logging, the underlying Log4J config is what's used):And in the log file:
Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
Hang on a second! After setting the log level down to WARN, this error message was no longer lost by overflow in my command prompt:



My log4j.properties file had this setting:


Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
And switching from backslash to slash (which i assume is correct) gives this error message:



So this is an access rights problem? OC4J doesn't have the rights to write to disk?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Try writing to a non-root directory?
Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
David Newton wrote:Try writing to a non-root directory?


It doesn't seem to matter at all where try to place the log files.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

It looks like you're missing the appropriate rights to write in these folders. Are you perhaps using Vista? Vista is a real pain when it comes to writing to the C: drive, with its annoying UAC.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
Rob Prime wrote:It looks like you're missing the appropriate rights to write in these folders. Are you perhaps using Vista? Vista is a real pain when it comes to writing to the C: drive, with its annoying UAC.


Windows 7.

I tried writing the logs in my user folder too, but that didn't work either.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How are you running the server?
Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
David Newton wrote:How are you running the server?


By double-clicking on a cmd file that does: C:\oracle\oc4j\bin\oc4j.cmd -start
Mats Andersson
Greenhorn

Joined: Jun 09, 2002
Posts: 11
I solved this. Found the log files in the folder where i have the bat-file that starts OC4J. Not the most logical place to me, but at least it's solved. Thanks for trying to help, guys.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Actually it is the most logical place. Your file location is relative in the configuration file, which means it's relative to the current working directory when the JVM is started.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: log4j refuses to write to file
 
Similar Threads
How to use different logging in different packages with log4j?
How to rotate catalina.out without restarting tomcat
Bugged with slf4j
problem read log4j configurations from tomcat
Logging SQL statements