• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

log4j: Log file not being generated

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, try to set debug to true in the log4j:configuration tag. Maybe it will give you some hint.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic