GeeCON Prague 2014*
The moose likes Other Open Source Projects and the fly likes log4j: Log file not being generated 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 "log4j: Log file not being generated" Watch "log4j: Log file not being generated" New topic
Author

log4j: Log file not being generated

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Hi,

I've used xml config file as below.



The problem is that, when I run the app, the log file (PostLogger.log) is not being generated and the output is getting dumped on the Console.

Is there something wrong with the config file? Why the output file is not being generated?
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
The problem is that, when I run the app, the log file (PostLogger.log) is not being generated and the output is getting dumped on the Console.


That's typo ... I mean to say PostLoader.log - as written in the config file - is not being generated.

Please help me rectify the problem.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

If you need all logs to be output to the file, then you need to set the appender to the root :


Instead, maybe you want to use the logger called "loader_debug" ?
If this is the case, then please post a line from your java code where you're getting the Log.
[ November 06, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10146
    
165

I mean to say PostLoader.log - as written in the config file - is not being generated.


Are you sure the file is not generated? Give a absolute name for the log file name in the log4j.xml and see if that gets created.

Something like:


[ November 06, 2006: Message edited by: Jaikiran Pai ]

[My Blog] [JavaRanch Journal]
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Later one is right, I want to use logger called "loader_debug".

Here is the code in which I configure and get the Logger:
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Hi Jaikiran,

I also tried using the absolute path name as below:



But the log file is still not being generated and instead the output is going to console!!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

That's strange. Once you've got "runLog", how do you use it ?
Could you please post one line where you're using runLog.

I've tried on my machine and the file is being generated.
By the way Category.getInstance is being deprecated in the latest version of log4j, so maybe you should use the following instead :
Logger log = Logger.getLogger("loader_debug");
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Yes, that's really strange for me as well. Here is how I used it in code:

runLog.debug("My output...");

Yesterday evening I tried with a text configuration file instead of xml and it worked for me. But I am still wondering why it is not working with this xml file. Do you see anything abnormal in this xml file?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

No I don't see anything particular. Maybe you should try to use the Logger tag instead of Category. I know they have the same meaning, but they are know as Logger now.
Which version of JUnit are you using ? Maybe you should try with the latest version too.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Also, try to set debug to true in the log4j:configuration tag. Maybe it will give you some hint.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
I'm not familiar with programmatic configuration using DocumentBuilderFactory...presumably you were having issues that made simple configuration by putting log4j.xml in the classpath not possible? Why are you doing that?

Regarding the configuration file:

1. Definitely turn debug on.

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/' debug="true">

I prefer to set this on the command line with -Dlog4j.debug

2. Get rid of this redundant piece. The <root> element configures the root logger, it doesn't accept any attributes as the additivity flag does not apply to the root logger, cannot have a name; info from Complete log4j manual (commercial - $ ).

<category name="root" additivity="false"></category>

3. put the additivity flag on the logger you don't want to be included up the hierarchy (loader_debug is the logger you don't want included up the hierarchy; root is up the hierarchy in this case). category/logger is probably not the problem, but logger is preferable.

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
Hi Carol,

This was actually a old code, written by someone else, so even I am not sure why it was that way.

I also tried a few other things with that code today morning and finally figured out that code was not able to load the file properly.

Anyway, thanks to all for your valuable inputs.
 
GeeCON Prague 2014
 
subject: log4j: Log file not being generated