Make log level in helma.util.Logging configurable, and make it derault to INFO.
This commit is contained in:
parent
d170d73565
commit
f36e390caa
2 changed files with 87 additions and 35 deletions
|
@ -228,31 +228,33 @@ public class FileLogger extends Logger implements Log {
|
||||||
*
|
*
|
||||||
* @return the timestamp for last midnight in millis
|
* @return the timestamp for last midnight in millis
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static long lastMidnight() {
|
private static long lastMidnight() {
|
||||||
return Logging.nextMidnight() - 86400000;
|
return Logging.nextMidnight() - 86400000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// override error() and fatal() to print error and fatal messages
|
||||||
|
// to the console, in addition to logging them to file.
|
||||||
|
|
||||||
public void error(Object parm1) {
|
public void error(Object parm1) {
|
||||||
System.err.println("Error: "+parm1);
|
System.err.println("Error: "+parm1);
|
||||||
info(parm1);
|
super.error(parm1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(Object parm1, Throwable parm2) {
|
public void error(Object parm1, Throwable parm2) {
|
||||||
System.err.println("Error: "+parm1);
|
System.err.println("Error: "+parm1);
|
||||||
System.err.println("See "+logfile+" for stack trace");
|
System.err.println("See "+logfile+" for stack trace");
|
||||||
info(parm1, parm2);
|
super.error(parm1, parm2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fatal(Object parm1) {
|
public void fatal(Object parm1) {
|
||||||
System.err.println("Fatal error: "+parm1);
|
System.err.println("Fatal: "+parm1);
|
||||||
info(parm1);
|
super.fatal(parm1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fatal(Object parm1, Throwable parm2) {
|
public void fatal(Object parm1, Throwable parm2) {
|
||||||
System.err.println("Fatal error: "+parm1);
|
System.err.println("Fatal: "+parm1);
|
||||||
System.err.println("See "+logfile+" for stack trace");
|
System.err.println("See "+logfile+" for stack trace");
|
||||||
info(parm1, parm2);
|
super.fatal(parm1, parm2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,15 +41,28 @@ public class Logger implements Log {
|
||||||
static long dateLastRendered;
|
static long dateLastRendered;
|
||||||
static String dateCache;
|
static String dateCache;
|
||||||
|
|
||||||
|
public final static int TRACE = 1;
|
||||||
|
public final static int DEBUG = 2;
|
||||||
|
public final static int INFO = 3;
|
||||||
|
public final static int WARN = 4;
|
||||||
|
public final static int ERROR = 5;
|
||||||
|
public final static int FATAL = 6;
|
||||||
|
|
||||||
|
int logLevel = INFO;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* zero argument constructor, only here for FileLogger subclass
|
* zero argument constructor, only here for FileLogger subclass
|
||||||
*/
|
*/
|
||||||
Logger() {}
|
Logger() {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a logger for a PrintStream, such as System.out.
|
* Create a logger for a PrintStream, such as System.out.
|
||||||
*/
|
*/
|
||||||
protected Logger(PrintStream out) {
|
protected Logger(PrintStream out) {
|
||||||
|
init();
|
||||||
writer = new PrintWriter(out);
|
writer = new PrintWriter(out);
|
||||||
canonicalName = out.toString();
|
canonicalName = out.toString();
|
||||||
|
|
||||||
|
@ -58,6 +71,25 @@ public class Logger implements Log {
|
||||||
entries = Collections.synchronizedList(new LinkedList());
|
entries = Collections.synchronizedList(new LinkedList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get loglevel from System properties
|
||||||
|
*/
|
||||||
|
private void init() {
|
||||||
|
String level = System.getProperty("helma.loglevel");
|
||||||
|
if ("trace".equalsIgnoreCase(level))
|
||||||
|
logLevel = TRACE;
|
||||||
|
else if ("debug".equalsIgnoreCase(level))
|
||||||
|
logLevel = DEBUG;
|
||||||
|
else if ("info".equalsIgnoreCase(level))
|
||||||
|
logLevel = INFO;
|
||||||
|
else if ("warn".equalsIgnoreCase(level))
|
||||||
|
logLevel = WARN;
|
||||||
|
else if ("error".equalsIgnoreCase(level))
|
||||||
|
logLevel = ERROR;
|
||||||
|
else if ("fatal".equalsIgnoreCase(level))
|
||||||
|
logLevel = FATAL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string representation of this Logger
|
* Return a string representation of this Logger
|
||||||
*/
|
*/
|
||||||
|
@ -124,76 +156,94 @@ public class Logger implements Log {
|
||||||
|
|
||||||
// methods to implement org.apache.commons.logging.Log interface
|
// methods to implement org.apache.commons.logging.Log interface
|
||||||
|
|
||||||
|
public boolean isTraceEnabled() {
|
||||||
|
return logLevel <= TRACE;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isDebugEnabled() {
|
public boolean isDebugEnabled() {
|
||||||
return true;
|
return logLevel <= DEBUG;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isErrorEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFatalEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInfoEnabled() {
|
public boolean isInfoEnabled() {
|
||||||
return true;
|
return logLevel <= INFO;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTraceEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWarnEnabled() {
|
public boolean isWarnEnabled() {
|
||||||
return true;
|
return logLevel <= WARN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isErrorEnabled() {
|
||||||
|
return logLevel <= ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFatalEnabled() {
|
||||||
|
return logLevel <= FATAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trace(Object parm1) {
|
public void trace(Object parm1) {
|
||||||
info(parm1);
|
if (logLevel <= TRACE)
|
||||||
|
log(parm1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trace(Object parm1, Throwable parm2) {
|
public void trace(Object parm1, Throwable parm2) {
|
||||||
info(parm1, parm2);
|
if (logLevel <= TRACE)
|
||||||
|
log(parm1.toString() + "\n" +
|
||||||
|
parm2.getStackTrace().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(Object parm1) {
|
public void debug(Object parm1) {
|
||||||
info(parm1);
|
if (logLevel <= DEBUG)
|
||||||
|
log(parm1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(Object parm1, Throwable parm2) {
|
public void debug(Object parm1, Throwable parm2) {
|
||||||
info(parm1, parm2);
|
if (logLevel <= DEBUG)
|
||||||
|
log(parm1.toString() + "\n" +
|
||||||
|
parm2.getStackTrace().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(Object parm1) {
|
public void info(Object parm1) {
|
||||||
|
if (logLevel <= INFO)
|
||||||
log(parm1.toString());
|
log(parm1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(Object parm1, Throwable parm2) {
|
public void info(Object parm1, Throwable parm2) {
|
||||||
log(parm1.toString() + "\n" + parm2.getStackTrace().toString());
|
if (logLevel <= INFO)
|
||||||
|
log(parm1.toString() + "\n" +
|
||||||
|
parm2.getStackTrace().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(Object parm1) {
|
public void warn(Object parm1) {
|
||||||
info(parm1);
|
if (logLevel <= WARN)
|
||||||
|
log(parm1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(Object parm1, Throwable parm2) {
|
public void warn(Object parm1, Throwable parm2) {
|
||||||
info(parm1, parm2);
|
if (logLevel <= WARN)
|
||||||
|
log(parm1.toString() + "\n" +
|
||||||
|
parm2.getStackTrace().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(Object parm1) {
|
public void error(Object parm1) {
|
||||||
info(parm1);
|
if (logLevel <= ERROR)
|
||||||
|
log(parm1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(Object parm1, Throwable parm2) {
|
public void error(Object parm1, Throwable parm2) {
|
||||||
info(parm1, parm2);
|
if (logLevel <= ERROR)
|
||||||
|
log(parm1.toString() + "\n" +
|
||||||
|
parm2.getStackTrace().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fatal(Object parm1) {
|
public void fatal(Object parm1) {
|
||||||
info(parm1);
|
if (logLevel <= FATAL)
|
||||||
|
log(parm1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fatal(Object parm1, Throwable parm2) {
|
public void fatal(Object parm1, Throwable parm2) {
|
||||||
info(parm1, parm2);
|
if (logLevel <= FATAL)
|
||||||
|
log(parm1.toString() + "\n" +
|
||||||
|
parm2.getStackTrace().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue