Skip to content

Commit

Permalink
Improve how Equinox trace is disabled with LoggerAdmin
Browse files Browse the repository at this point in the history
Use EQUINOX.TRACE key to disable trace also with any value
that is not LogLevel.TRACE.
  • Loading branch information
tjwatson committed Feb 1, 2025
1 parent bb16215 commit e35221a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ private void doTestEnableTrace(String loggerContextName) {
logEntry.getLoggerName());
}

// remove all debug options which should disable debug trace
rootLogLevels.clear();
rootLogLevels.put(Debug.EQUINOX_TRACE, LogLevel.TRACE);
// Setting the EQUINOX.TRACE to anything but trace should disable
rootLogLevels.put(Debug.EQUINOX_TRACE, LogLevel.AUDIT);
rootContext.setLogLevels(rootLogLevels);
assertFalse("Expected debug to be disabled.", debugOptions.isDebugEnabled());
assertEquals("Expected no debug Options.", 0, debugOptions.getOptions().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,21 @@ private void enableEquinoxTrace(EquinoxLoggerContext systemBundleLoggerContext)
}
Map<String, LogLevel> logLevels = systemBundleLoggerContext.getEffectiveLogLevels();
LogLevel equinoxTrace = logLevels.remove(Debug.EQUINOX_TRACE);
if (equinoxTrace != LogLevel.TRACE) {
if (equinoxTrace == null) {
return;
}
DebugOptions debugOptions = getConfiguration().getDebugOptions();
Map<String, String> options = debugOptions.getOptions();
options.clear();
boolean enable = false;
for (Entry<String, LogLevel> level : logLevels.entrySet()) {
if (level.getValue() == LogLevel.TRACE
&& !(EQUINOX_LOGGER_NAME.equals(level.getKey()) || PERF_LOGGER_NAME.equals(level.getKey()))) {
options.put(level.getKey(), Boolean.TRUE.toString());
enable = true;
if (equinoxTrace == LogLevel.TRACE) {
// enable trace options if the EQUINOX.TRACE is set to trace
for (Entry<String, LogLevel> level : logLevels.entrySet()) {
if (level.getValue() == LogLevel.TRACE && !(EQUINOX_LOGGER_NAME.equals(level.getKey())
|| PERF_LOGGER_NAME.equals(level.getKey()))) {
options.put(level.getKey(), Boolean.TRUE.toString());
enable = true;
}
}
}
debugOptions.setOptions(options);
Expand Down

0 comments on commit e35221a

Please sign in to comment.