• 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

Customize Logger Problem

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm working on a project which requires a customize logger where there are a predefined log files to log the output to depending on different business functionalities. For eg. all logging (including different level, debug, error, ...) for classes implementing business function A will go to log file A.

For eg. if I've a StringUtility.isEmpty() and a debug log is implemented there and as different classes implementing different business functionalities can invoke this method, any advise on how do I implement my customize logger such that it'll know which log file to use. For eg. classes implementing business function A invoke StringUtility.isEmpty(), logging should go to log file A. If the class implementing business function B, call this StringUtility.isEmpty(), logging should output to log file B.

I'm following the standard instantiation of the logger object is as follows:



Please advise, thanks!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Too difficult a question for us beginners. Moving.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you really get "this" to work after the static keyword?
 
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
Apart from that... if you have the requirement to log to two different places, then you will need two different loggers.
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Apart from that... if you have the requirement to log to two different places, then you will need two different loggers.



Yes, I will need different loggers but the problem is when there are logging in the the common classes, how can the logger know which log to output to?
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Can you really get "this" to work after the static keyword?



Sorry, typed out from my memory. Have updated the codes.
 
Paul Clapham
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

ABu NeNe wrote:Yes, I will need different loggers but the problem is when there are logging in the the common classes, how can the logger know which log to output to?



You do that in the configuration. But since you need two loggers, then think about it. You can't just use the class name to identify the logger, because if you do that way then you can't have two loggers.
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've the following idea, please take a look:

1. implement the logger class as a singleton
2. create and cache the different logger objects (different logger with different log files) using hashtable when the logger has been instantiated by different classes implementing the business functionalities
3. when the common classes have been invoked by the different classes implementing the business functionalities, logger will use the new Throwable().fillInStackTrace().getStackTrace() to find out the class invoking and lookup in the cache to retrieve the relevant logger.

The concern I've is performance as the operation is quite expensive. Please advise if there are any concern using this approach. Any better suggestion is always welcome.
 
Paul Clapham
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
My advice is to not do any of that. Either use the built-in classes in the java.util.logging package, or use log4j to do your logging.

Of course if it's really too expensive, then you would just choose not to do it. But right now you have no idea of the costs and haven't measured them at all. So don't try to optimize it because it really isn't too expensive. Just use an existing logging solution and get on with the more important parts of the project.
reply
    Bookmark Topic Watch Topic
  • New Topic