Total members 11890 |It is currently Fri Apr 19, 2024 11:10 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Logging based on severity
java code
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);
}
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Logging based on severity Level : INFO,Warning,ERROR,Debu
 Java Logging     -  
 Free Work at Home Info Pack     -  
 Network Interface Adapter Info using Java APIs.     -  
 Sound Level Meter     -  
 level of conformance in multicast     -  
 high-level thread states     -  
 file exists in upper level folder link     -  
 Cookie based login in php     -  
 prapose me a web based mini project     -  
 Takes a string apart based on a delimiter     -  



Topic Tags

Java Files and I/O






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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