diff options
author | Thomas Watson | 2008-02-13 19:17:39 +0000 |
---|---|---|
committer | Thomas Watson | 2008-02-13 19:17:39 +0000 |
commit | 9066fd5fc490f6188a2d5fca592a0b3ef653dd5d (patch) | |
tree | b622b22cdaac966558b5fd1f5bed850196a51ebc /bundles/org.eclipse.osgi/eclipseAdaptor | |
parent | 24bf22274a62fa2b11318d82bad1d215a4725986 (diff) | |
download | rt.equinox.framework-9066fd5fc490f6188a2d5fca592a0b3ef653dd5d.tar.gz rt.equinox.framework-9066fd5fc490f6188a2d5fca592a0b3ef653dd5d.tar.xz rt.equinox.framework-9066fd5fc490f6188a2d5fca592a0b3ef653dd5d.zip |
Bug 215361 Support differing log levels
Diffstat (limited to 'bundles/org.eclipse.osgi/eclipseAdaptor')
-rw-r--r-- | bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseLog.java | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseLog.java b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseLog.java index f311311d0..ef303e0e9 100644 --- a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseLog.java +++ b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseLog.java @@ -55,6 +55,8 @@ public class EclipseLog implements FrameworkLog { /** The minimum size limit for log rotation */ public static final int LOG_SIZE_MIN = 10; + /** The system property used to specify the log level */ + public static final String PROP_LOG_LEVEL = "eclipse.log.level"; //$NON-NLS-1$ /** The system property used to specify size a log file can grow before it is rotated */ public static final String PROP_LOG_SIZE_MAX = "eclipse.log.size.max"; //$NON-NLS-1$ /** The system property used to specify the maximim number of backup log files to use */ @@ -88,6 +90,8 @@ public class EclipseLog implements FrameworkLog { int maxLogFiles = DEFAULT_LOG_FILES; int backupIdx = 0; + private int logLevel = FrameworkLogEntry.OK; + /** * Constructs an EclipseLog which uses the specified File to log messages to * @param outFile a file to log messages to @@ -290,6 +294,8 @@ public class EclipseLog implements FrameworkLog { public synchronized void log(FrameworkLogEntry logEntry) { if (logEntry == null) return; + if (!isLoggable(logEntry)) + return; try { checkLogFileSize(); openFile(); @@ -397,17 +403,17 @@ public class EclipseLog implements FrameworkLog { * @return a date string. */ protected String getDate(Date date) { - Calendar c = Calendar.getInstance(); - c.setTime(date); - StringBuffer sb = new StringBuffer(); - appendPaddedInt(c.get(Calendar.YEAR), 4, sb).append('-'); - appendPaddedInt(c.get(Calendar.MONTH) + 1, 2, sb).append('-'); - appendPaddedInt(c.get(Calendar.DAY_OF_MONTH), 2, sb).append(' '); - appendPaddedInt(c.get(Calendar.HOUR_OF_DAY), 2, sb).append(':'); - appendPaddedInt(c.get(Calendar.MINUTE), 2, sb).append(':'); - appendPaddedInt(c.get(Calendar.SECOND), 2, sb).append('.'); - appendPaddedInt(c.get(Calendar.MILLISECOND), 3, sb); - return sb.toString(); + Calendar c = Calendar.getInstance(); + c.setTime(date); + StringBuffer sb = new StringBuffer(); + appendPaddedInt(c.get(Calendar.YEAR), 4, sb).append('-'); + appendPaddedInt(c.get(Calendar.MONTH) + 1, 2, sb).append('-'); + appendPaddedInt(c.get(Calendar.DAY_OF_MONTH), 2, sb).append(' '); + appendPaddedInt(c.get(Calendar.HOUR_OF_DAY), 2, sb).append(':'); + appendPaddedInt(c.get(Calendar.MINUTE), 2, sb).append(':'); + appendPaddedInt(c.get(Calendar.SECOND), 2, sb).append('.'); + appendPaddedInt(c.get(Calendar.MILLISECOND), 3, sb); + return sb.toString(); } private StringBuffer appendPaddedInt(int value, int pad, StringBuffer buffer) { @@ -661,5 +667,26 @@ public class EclipseLog implements FrameworkLog { maxLogFiles = DEFAULT_LOG_FILES; } } + + String newLogLevel = secureAction.getProperty(PROP_LOG_LEVEL); + if (newLogLevel != null) { + if (newLogLevel.equals("ERROR")) //$NON-NLS-1$ + logLevel = FrameworkLogEntry.ERROR; + else if (newLogLevel.equals("WARNING")) //$NON-NLS-1$ + logLevel = FrameworkLogEntry.ERROR | FrameworkLogEntry.WARNING; + else if (newLogLevel.equals("INFO")) //$NON-NLS-1$ + logLevel = FrameworkLogEntry.INFO | FrameworkLogEntry.ERROR | FrameworkLogEntry.WARNING | FrameworkLogEntry.CANCEL; + else + logLevel = FrameworkLogEntry.OK; // OK (0) means log everything + } + } + + /** + * Determines if the log entry should be logged based on log level. + */ + private boolean isLoggable(FrameworkLogEntry entry) { + if (logLevel == 0) + return true; + return (entry.getSeverity() & logLevel) != 0; } } |