• 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

Java Logger Puzzle

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to write a utility class to get Loggers with a certain Handler Formatter. The output from the following code is

Can anyone explain why there are only messages from the last logger?

Thanks,
Glenn

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just tried this and get the same result as you, I'd be lieing if I said I knew why, but have experimented and think its something to do with using the same stream in each logger, possibly different threads accessing the same stream ?.

If the method to create the handler creates a handle using a different FileOutputStream (outputting to different files) for each logger then it works as expected, and if it uses the same file then only the 1st logger outputs. I tried creating a handler that flushes the stream after each "publish" but that didn't have any effect.

I'd also be interested if anyone can shed any light on this.
 
michael warren
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interestingly the following handler works as expected



The documentation for StreamHandler says "This is primarily intended as a base class or support class to be used in implementing other logging Handlers" implying that you're not expected to use it directly, think I need to read more on the Logging package in general to understand why it doesn't work as expected.
 
reply
    Bookmark Topic Watch Topic
  • New Topic