Java gurus in here please

Discussion in 'OT Technology' started by babygodzilla, Feb 2, 2008.

  1. babygodzilla

    babygodzilla I love rice

    Nov 5, 2001
    Likes Received:
    I have a question about Log4J. Is there a way such that I don't have to declare

    Logger log = Logger.getLogger(ClassName.class);
    in every class i want to log messages in? I know that you can call the root logger, but that is ill-advised and I believe if you use that you won't know which class the message is coming from. I want to be able to

    1) know which class is printing what message, as always, but
    2) not have to declare the above line of code in every Class.

  2. Dnepr

    Dnepr Guest

    Create a separate class that will do that.

    Make a get method which will take ClassName.class and return logger.

  3. Jkuao

    Jkuao New Member

    Jan 10, 2004
    Likes Received:
    You could create a parent class and declare the Log4J instance within the constructor. If you have a lot of classes within this package it can be a time saver. You could also declare everything as having an interface to a class that does your Log4J. This may not be good style depending on your architecture.

    It's been a while since I've done this so maybe wait for someone to confirm. Damn all the proprietary junk I've been doing. Makes my Java skills so rusty.

Share This Page