Thu Apr 25, 2013 11:58 pm
import java.util.logging.Level;
import java.util.logging.Logger;
public class MyLogger {
protected Logger logger;
private final String className;
protected MyLogger(final Class sourceClass) {
this.className = sourceClass.getSimpleName();
this.logger = Logger.getLogger(sourceClass.getName());
}
public static MyLogger getInstance(final Class sourceClass) {
return new MyLogger(sourceClass);
}
public void logInfo(final String methodName, final String msg) {
if (this.isInfoLoggable()) {
this.logger.logp(Level.INFO, this.className, methodName, msg);
}
}
/**
Log Information about something
*/
public void logInfo(final String methodName, final String msg,
final Object param) {
if (this.isInfoLoggable()) {
this.logger.logp(Level.INFO, this.className, methodName, msg, param);
}
}
/**
* Log a Warning message
*/
public void logWarning(final String methodName, final String msg) {
if (this.isWarningLoggable()) {
this.logger.logp(Level.WARNING, this.className, methodName, msg);
}
}
/**
Log error
*/
public void logError(final String methodName, final String msg) {
if (this.isErrorLoggable()) {
this.logger.logp(Level.SEVERE, this.className, methodName, msg);
}
}
public void debug(final String methodName, final String msg) {
if (this.isDebugLoggable()) {
this.logger.logp(Level.FINE, this.className, methodName, msg);
}
}
public void traceEntry(final String methodName) {
if (this.isTraceEntryLoggable()) {
this.logger.entering(this.className, methodName);
}
}
public void traceExit(final String methodName) {
if (this.isTraceExitLoggable()) {
this.logger.exiting(this.className, methodName);
}
}
public void traceExit(final String methodName, final Object result) {
if (this.isTraceExitLoggable()) {
this.logger.exiting(this.className, methodName, result);
}
}
public void traceException(final String methodName, final String msg,
final Throwable thrown) {
if (this.isTraceExceptionLoggable()) {
this.logger.logp(Level.FINE, this.className, methodName, msg, thrown);
}
}
public Boolean isInfoLoggable() {
return this.logger.isLoggable(Level.INFO);
}
public Boolean isWarningLoggable() {
return this.logger.isLoggable(Level.WARNING);
}
public Boolean isErrorLoggable() {
return this.logger.isLoggable(Level.SEVERE);
}
public Boolean isDebugLoggable() {
return this.logger.isLoggable(Level.FINE);
}
public Boolean isTraceEntryLoggable() {
return this.logger.isLoggable(Level.FINER);
}
public Boolean isTraceExitLoggable() {
return this.logger.isLoggable(Level.FINER);
}
public Boolean isTraceExceptionLoggable() {
return this.logger.isLoggable(Level.FINE);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.