Only use vt100 escape codes if they're enabled via -Dlog_vt100=true.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@769 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DefaultLogProvider.java,v 1.5 2002/05/31 20:45:26 mdb Exp $
|
// $Id: DefaultLogProvider.java,v 1.6 2002/05/31 21:06:26 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -34,6 +34,20 @@ import java.util.Hashtable;
|
|||||||
*/
|
*/
|
||||||
public class DefaultLogProvider implements LogProvider
|
public class DefaultLogProvider implements LogProvider
|
||||||
{
|
{
|
||||||
|
public DefaultLogProvider ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// enable vt100 escape codes if requested
|
||||||
|
String pstr = System.getProperty("log_vt100");
|
||||||
|
if (!StringUtil.blank(pstr)) {
|
||||||
|
_useVT100 = pstr.equalsIgnoreCase("true");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SecurityException se) {
|
||||||
|
// nothing to worry about
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void log (
|
public synchronized void log (
|
||||||
int level, String moduleName, String message)
|
int level, String moduleName, String message)
|
||||||
{
|
{
|
||||||
@@ -71,9 +85,9 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append(_format.format(new Date())).append(" ");
|
buf.append(_format.format(new Date())).append(" ");
|
||||||
if (level == Log.WARNING) {
|
if (level == Log.WARNING && _useVT100) {
|
||||||
buf.append(BOLD);
|
buf.append(BOLD);
|
||||||
} else if (level == Log.DEBUG) {
|
} else if (level == Log.DEBUG && _useVT100) {
|
||||||
buf.append(REVERSE);
|
buf.append(REVERSE);
|
||||||
}
|
}
|
||||||
buf.append(LEVEL_CHARS[level]).append(" ");
|
buf.append(LEVEL_CHARS[level]).append(" ");
|
||||||
@@ -83,7 +97,8 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
|
|
||||||
// if we wrap, we include the module name in the wrapped text
|
// if we wrap, we include the module name in the wrapped text
|
||||||
int wrapwid = LOG_LINE_LENGTH - buf.length();
|
int wrapwid = LOG_LINE_LENGTH - buf.length();
|
||||||
buf.append(UNDERLINE).append(moduleName).append(PLAIN).append(": ");
|
buf.append(_useVT100 ? UNDERLINE : "").append(moduleName);
|
||||||
|
buf.append(_useVT100 ? PLAIN : "").append(": ");
|
||||||
|
|
||||||
// we'll be wrapping the log lines
|
// we'll be wrapping the log lines
|
||||||
int remain = message.length(), offset = 0;
|
int remain = message.length(), offset = 0;
|
||||||
@@ -106,6 +121,9 @@ public class DefaultLogProvider implements LogProvider
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether or not to use the vt100 escape codes. */
|
||||||
|
protected boolean _useVT100 = false;
|
||||||
|
|
||||||
/** The default log level. */
|
/** The default log level. */
|
||||||
protected int _level = Log.INFO;
|
protected int _level = Log.INFO;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user