net.sf.sanity4j.util.QaLoggerSystemOutImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
package net.sf.sanity4j.util;
import java.io.PrintStream;
/**
* This logger implementation just uses System.out / System.err
* to print message for running from a command-line, within eclipse etc.
*
* @author Yiannis Paschalidis
* @since Sanity4J 1.0
*/
public class QaLoggerSystemOutImpl extends QaLogger
{
/** Hide the constructor - instances must be obtained using getInstance. */
protected QaLoggerSystemOutImpl()
{
// Hide the constructor - instances must be obtained using getInstance.
}
/**
* Write a message to the log with the log level of MSG_DEBUG .
* @param message The text to log. Should not be null
.
*/
public void debug(final String message)
{
log(message, System.out);
}
/**
* Write a message to the log with the log level of MSG_DEBUG .
* @param message The text to log. Should not be null
.
* @param throwable the throwable, presumably caught in a catch block.
*/
public void debug(final String message, final Throwable throwable)
{
String messageWithStrackTrace = stackTraceToString(message, throwable);
log(messageWithStrackTrace, System.out);
}
/**
* Write a message to the log with the log level of MSG_INFO .
* @param message The text to log. Should not be null
.
*/
public void info(final String message)
{
log(message, System.out);
}
/**
* Write a message to the log with the log level of MSG_WARN .
* @param message The text to log. Should not be null
.
*/
public void warn(final String message)
{
log(message, System.out);
}
/**
* Write a message to the log with the log level of MSG_WARN .
* @param message The text to log. Should not be null
.
* @param throwable the throwable, presumably caught in a catch block.
*/
public void warn(final String message, final Throwable throwable)
{
String messageWithStrackTrace = stackTraceToString(message, throwable);
log(messageWithStrackTrace, System.out);
}
/**
* Write a message to the log with the log level of MSG_ERR .
* @param message The text to log. Should not be null
.
*/
public void error(final String message)
{
log(message, System.err);
}
/**
* Write a message to the log with the log level of MSG_ERR .
* @param message The text to log. Should not be null
.
* @param throwable the throwable, presumably caught in a catch block.
*/
public void error(final String message, final Throwable throwable)
{
String messageWithStrackTrace = stackTraceToString(message, throwable);
log(messageWithStrackTrace, System.err);
}
/**
* Logs a message to the underlying output stream.
* @param message the message to log
* @param stream the stream to write to
*/
private void log(final String message, final PrintStream stream)
{
stream.println(message);
}
}