Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > lib of static class methods, java logging

Reply
Thread Tools

lib of static class methods, java logging

 
 
frank
Guest
Posts: n/a
 
      07-14-2005
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

 
Reply With Quote
 
 
 
 
Boudewijn Dijkstra
Guest
Posts: n/a
 
      07-14-2005

"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...


 
Reply With Quote
 
 
 
 
Hemal Pandya
Guest
Posts: n/a
 
      07-14-2005
>
> 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);

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
any python wrapper to call .lib static library(ufmod.lib)? est Python 1 02-16-2008 10:56 AM
Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib) Avi Perl Misc 0 04-17-2007 09:20 PM
a logging/trace lib for java frank Java 7 06-16-2005 11:19 PM
java.util.logging, where to put logging.properties? janne Java 0 09-10-2004 10:18 AM
[java.util.logging] logging only to _one_ file Stefan Siegl Java 0 08-27-2003 12:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57