I have a logging function that takes the calling object as a parameter. I then call getClass().getSimpleName() on it so that I can easily get the class name to add to my log en
Wouldn't implementing some sort of Singleton do what you need?
public class LogUtility {
private final String loggingFrom;
private static LogUtility instance;
public static LogUtility getLogger() {
if(instance == null)
this.instance = new LogUtility();
StackTraceElement [] s = new RuntimeException().getStackTrace();
this.instance.setLoggingFrom(s[1].getClassName())
return this.instance;
}
private LogUtility() {}
private void setLoggingFrom(String loggingClassName){
this.loggingFrom = loggingClassName;
}
public void log( String message ) {
System.out.println( loggingFrom + message );
}
}
Usage (anywhere in your project):
LogUtility.getLogger().log("Message");