F
Fencer
Hello, I've been tasked with implementing a logging feature to a program
consisting of maybe 100 classes. I've implemented the GUI side of this
feature (a window where this information will be displayed, it can go to
a file as well).
Now I'm wondering what the best way is to make my logger available to
the classes that needs to use it. I could add a parameter to the
constructors, I suppose, but that doesn't feel right to me. The whole
idea is to replace many System.out/err.println() calls that are
scattered throughout the code with this logging class.
The users of the logging class don't know or care if the logger just
writes to a file, and/or displays it in a special window or if it's even
turned of.
Maybe I could use a singleton as my logger? So when a class A wants to
log something it obtains a logger object and uses it. I want the user to
be able to change the behavior of the logging during runtime, and I
think I can do that with this approach. But since I'm not a seasoned
Java programmer I ask here for advice.
Also, this program is single-threaded, at least, I'm not creating any
new threads myself explicitly. I'm using Java 1.6.0_13.
- Fencer
consisting of maybe 100 classes. I've implemented the GUI side of this
feature (a window where this information will be displayed, it can go to
a file as well).
Now I'm wondering what the best way is to make my logger available to
the classes that needs to use it. I could add a parameter to the
constructors, I suppose, but that doesn't feel right to me. The whole
idea is to replace many System.out/err.println() calls that are
scattered throughout the code with this logging class.
The users of the logging class don't know or care if the logger just
writes to a file, and/or displays it in a special window or if it's even
turned of.
Maybe I could use a singleton as my logger? So when a class A wants to
log something it obtains a logger object and uses it. I want the user to
be able to change the behavior of the logging during runtime, and I
think I can do that with this approach. But since I'm not a seasoned
Java programmer I ask here for advice.
Also, this program is single-threaded, at least, I'm not creating any
new threads myself explicitly. I'm using Java 1.6.0_13.
- Fencer