lib of static class methods, java logging

Discussion in 'Java' started by frank, Jul 14, 2005.

  1. frank

    frank Guest

    Was wondering what might be the better way to do something in java. I
    have a class of static methods that are a library and I want to use the
    java. To do that I need to use the log variable I have setup already.
    What is the best way to initialize and use that in the methods?

    1. Create an instance variable in the static class lib for log and do a
    new on the thing when start my program

    _util = new JBFSAUtility(logger);
    ....

    static Logger logger;

    JBFSAUtility(Logger l)
    {
    logger = l;
    }
    ......


    2. Pass the log variable to each method?

    JBFSAUtility.method1(Logger l);

    Thanks,

    Frank
     
    frank, Jul 14, 2005
    #1
    1. Advertising

  2. "frank" <> schreef in bericht
    news:dysBe.1865$...
    > Was wondering what might be the better way to do something in java. I have a
    > class of static methods that are a library and I want to use the java. To
    > do that I need to use the log variable I have setup already. What is the
    > best way to initialize and use that in the methods?
    >
    > 1. Create an instance variable in the static class lib for log and do a new
    > on the thing when start my program
    >
    > _util = new JBFSAUtility(logger);
    > ...
    >
    > static Logger logger;
    >
    > JBFSAUtility(Logger l)
    > {
    > logger = l;
    > }
    > .....


    This code will overwrite static member logger everytime a new object is
    created. If class JBFSAUtility should use the same logger in the entire VM,
    then keep it static and don't use a constructor at all. Otherwise, don't make
    logger static, and use JBFSAUtility objects.

    > 2. Pass the log variable to each method?
    >
    > JBFSAUtility.method1(Logger l);


    This code is even less sensible from a object-oriented point of view...
     
    Boudewijn Dijkstra, Jul 14, 2005
    #2
    1. Advertising

  3. frank

    Hemal Pandya Guest

    >
    > static Logger logger;
    >
    > JBFSAUtility(Logger l)
    > {
    > logger = l;
    > }


    In the interest of symmetry consider providing a static method
    setLogger in JBFSAUtility. You would still have to worry about some
    other method of the class getting called before the setLogger is
    called, but that problem you have to tackle even with the current
    approach.

    So the call

    _util = new JBFSAUtility(logger);

    changes to

    JBFSAUtility.setLogger(logger);
     
    Hemal Pandya, Jul 14, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    0
    Views:
    988
    Stefan Siegl
    Aug 27, 2003
  2. SaravanaKumar
    Replies:
    6
    Views:
    9,522
    Tony Morris
    Oct 19, 2004
  3. frank
    Replies:
    7
    Views:
    569
  4. est
    Replies:
    1
    Views:
    664
    Diez B. Roggisch
    Feb 16, 2008
  5. Kenneth McDonald
    Replies:
    5
    Views:
    386
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page