• 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] What happens initializing more than one logger?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose that i've setted the .properties files in which i declared a rootlogger and an appender to output inside a file.

Now i've two classes and in each one i intitialize a brand new Logger object
Logger log= (Logger) Logger.getStdLogger(getClass());

The output log will be wrote inside the same output files for both classes? Loggers inside property file are in some ways related to the instances inside the java classes?
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see this is a problem.

Each class initiates its own logger. It just happens the file class writes to is the same.

An analogy to what you are asking is: application servers like Tomcat, JBoss, Glassfish all write to the same server log file for all applications.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's only a small number of loggers. As the API documentation for the getLogger method says:

The documentation wrote:Retrieve a logger named according to the value of the name parameter. If the named logger already exists, then the existing instance will be returned. Otherwise, a new instance is created.



In other words, your code doesn't actually initialize a brand-new Logger object for each of the two classes. It seems that you have made some extra assumption that I don't understand.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic