You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.1 KiB
84 lines
2.1 KiB
package com.jotuntech.sketcher.common;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.PrintStream;
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Locale;
|
|
|
|
public class Log {
|
|
/** Log debug messages? */
|
|
private final static boolean debug = true;
|
|
|
|
/** Log info messages? */
|
|
private final static boolean info = true;
|
|
|
|
/** Log error messages? */
|
|
private final static boolean error = true;
|
|
|
|
/** Log warning messages? */
|
|
private final static boolean warn = true;
|
|
|
|
/** Date format */
|
|
private final static DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", Locale.US);
|
|
|
|
/**
|
|
* Logs the specified debug message.
|
|
*
|
|
* @param message Message to log.
|
|
*/
|
|
public final static void debug(String message) {
|
|
if(debug) {
|
|
log(df.format(new Date()) + " [DEBUG: " + Thread.currentThread().getName() + "] " + message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Logs the specified info message.
|
|
*
|
|
* @param message Message to log.
|
|
*/
|
|
public final static void info(String message) {
|
|
if(info) {
|
|
log(df.format(new Date()) + " [INFO: " + Thread.currentThread().getName() + "] " + message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Logs the specified error message.
|
|
*
|
|
* @param message Message to log.
|
|
*/
|
|
public final static void error(String message) {
|
|
if(error) {
|
|
log(df.format(new Date()) + " [ERROR: " + Thread.currentThread().getName() + "] " + message);
|
|
}
|
|
}
|
|
|
|
public final static void error(Throwable t) {
|
|
if(error) {
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
PrintStream ps = new PrintStream(baos);
|
|
t.printStackTrace(ps);
|
|
String message = baos.toString();
|
|
ps.close();
|
|
log(df.format(new Date()) + " [ERROR: " + Thread.currentThread().getName() + "] " + message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Logs the specified warn message.
|
|
*
|
|
* @param message Message to log.
|
|
*/
|
|
public final static void warn(String message) {
|
|
if(warn) {
|
|
log(df.format(new Date()) + " [WARN: " + Thread.currentThread().getName() + "] " + message);
|
|
}
|
|
}
|
|
|
|
private final static void log(String message) {
|
|
System.err.println(message);
|
|
}
|
|
}
|
|
|