mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-17 07:02:54 -04:00
Added log levels to the Log, as well a verbose level
This commit is contained in:
@@ -41,14 +41,16 @@ import resources.control.Service;
|
||||
public class Log {
|
||||
|
||||
private static final DateFormat LOG_FORMAT = new SimpleDateFormat("dd-mm-yy HH:mm:ss.SSS");
|
||||
private static final Log LOG = new Log("log.txt");
|
||||
private static final Log LOG = new Log("log.txt", LogLevel.VERBOSE);
|
||||
|
||||
private final File file;
|
||||
private BufferedWriter writer;
|
||||
private LogLevel level;
|
||||
private boolean open;
|
||||
|
||||
private Log(String filename) {
|
||||
private Log(String filename, LogLevel level) {
|
||||
this.file = new File(filename);
|
||||
this.level = level;
|
||||
open = false;
|
||||
}
|
||||
|
||||
@@ -72,6 +74,14 @@ public class Log {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void setLevel(LogLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
private synchronized LogLevel getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
protected static final void start() {
|
||||
try {
|
||||
LOG.open();
|
||||
@@ -88,15 +98,30 @@ public class Log {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum level for logs to be reported. This is according to the
|
||||
* following order: VERBOSE, DEBUG, INFO, WARNING, ERROR, then ASSERT.
|
||||
* @param level the minimum log level, inclusively. Default is VERBOSE
|
||||
*/
|
||||
public static final void setLogLevel(LogLevel level) {
|
||||
synchronized (LOG) {
|
||||
LOG.setLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the string to the server log file, formatted to display the log
|
||||
* severity, time, tag and message.
|
||||
* @param level the log level of this message between INFO and ASSERT
|
||||
* @param level the log level of this message between VERBOSE and ASSERT
|
||||
* @param tag the tag to use for the log
|
||||
* @param str the format string for the log
|
||||
* @param args the string format arguments, if specified
|
||||
*/
|
||||
public static final void log(LogLevel level, String tag, String str, Object ... args) {
|
||||
synchronized (LOG) {
|
||||
if (LOG.getLevel().compareTo(level) > 0)
|
||||
return;
|
||||
}
|
||||
String date;
|
||||
synchronized (LOG_FORMAT) {
|
||||
date = LOG_FORMAT.format(System.currentTimeMillis());
|
||||
@@ -114,26 +139,24 @@ public class Log {
|
||||
|
||||
/**
|
||||
* Logs the string to the server log file, formatted to display the log
|
||||
* severity as INFO, as well as the time, tag and message.
|
||||
* @param level the log level of this message between INFO and ASSERT
|
||||
* severity as VERBOSE, as well as the time, tag and message.
|
||||
* @param tag the tag to use for the log
|
||||
* @param message the format string for the log
|
||||
* @param args the string format arguments, if specified
|
||||
*/
|
||||
public static final void i(String tag, String message, Object ... args) {
|
||||
log(LogLevel.INFO, tag, message, args);
|
||||
public static final void v(String tag, String message, Object ... args) {
|
||||
log(LogLevel.VERBOSE, tag, message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the string to the server log file, formatted to display the log
|
||||
* severity as INFO, as well as the time, service name and message.
|
||||
* @param level the log level of this message between INFO and ASSERT
|
||||
* severity as VERBOSE, as well as the time, service name and message.
|
||||
* @param service the service outputting this log info
|
||||
* @param message the format string for the log
|
||||
* @param args the string format arguments, if specified
|
||||
*/
|
||||
public static final void i(Service service, String message, Object ... args) {
|
||||
log(LogLevel.INFO, service.getClass().getSimpleName(), message, args);
|
||||
public static final void v(Service service, String message, Object ... args) {
|
||||
log(LogLevel.VERBOSE, service.getClass().getSimpleName(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,6 +181,28 @@ public class Log {
|
||||
log(LogLevel.DEBUG, service.getClass().getSimpleName(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the string to the server log file, formatted to display the log
|
||||
* severity as INFO, as well as the time, tag and message.
|
||||
* @param tag the tag to use for the log
|
||||
* @param message the format string for the log
|
||||
* @param args the string format arguments, if specified
|
||||
*/
|
||||
public static final void i(String tag, String message, Object ... args) {
|
||||
log(LogLevel.INFO, tag, message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the string to the server log file, formatted to display the log
|
||||
* severity as INFO, as well as the time, service name and message.
|
||||
* @param service the service outputting this log info
|
||||
* @param message the format string for the log
|
||||
* @param args the string format arguments, if specified
|
||||
*/
|
||||
public static final void i(Service service, String message, Object ... args) {
|
||||
log(LogLevel.INFO, service.getClass().getSimpleName(), message, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the string to the server log file, formatted to display the log
|
||||
* severity as WARN, as well as the time, tag and message.
|
||||
@@ -225,8 +270,9 @@ public class Log {
|
||||
}
|
||||
|
||||
public static enum LogLevel {
|
||||
INFO ('I'),
|
||||
VERBOSE ('V'),
|
||||
DEBUG ('D'),
|
||||
INFO ('I'),
|
||||
WARN ('W'),
|
||||
ERROR ('E'),
|
||||
ASSERT ('A');
|
||||
|
||||
Reference in New Issue
Block a user