Let logging to file respect log level (#8264)

This change fixes a regression introduced in #7918, which prevented the execution from setting the right log level either via env var or parameter.

Now passing either of the options returns logs of the expected level in the log file:
- `ENSO_LOG_TO_FILE_LOG_LEVEL = trace`
- ... `-vv` ...

Fixes #8274
This commit is contained in:
Hubert Plociniczak 2023-11-14 12:59:27 +01:00 committed by GitHub
parent 5baec46466
commit c649ed87af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 12 deletions

View File

@ -37,9 +37,9 @@ logging-service {
org.eclipse.jgit = error
io.methvin.watcher = error
# Log levels to limit during very verbose setting:
#org.enso.languageserver.protocol.json.JsonConnectionController = debug
#org.enso.jsonrpc.JsonRpcServer = debug
#org.enso.languageserver.runtime.RuntimeConnector = debug
org.enso.languageserver.protocol.json.JsonConnectionController = debug
org.enso.jsonrpc.JsonRpcServer = debug
org.enso.languageserver.runtime.RuntimeConnector = debug
}
appenders = [
{
@ -56,7 +56,7 @@ logging-service {
default-appender = socket
default-appender = ${?ENSO_APPENDER_DEFAULT}
log-to-file {
enable = false
enable = false ## Will have effect only if language server is not using socket appender
enable = ${?ENSO_LOG_TO_FILE}
log-level = debug
log-level = ${?ENSO_LOG_TO_FILE_LOG_LEVEL}

View File

@ -28,9 +28,11 @@ public final class ConsoleAppender extends Appender {
@Override
public boolean setupForPath(
Level logLevel, Path logRoot, String logPrefix, LoggerSetup loggerSetup) {
if (loggerSetup.getConfig().logToFile().enabled()) {
loggerSetup.setupFileAppender(
loggerSetup.getConfig().logToFile().logLevel(), logRoot, logPrefix);
LogToFile logToFileOpt = loggerSetup.getConfig().logToFile();
if (logToFileOpt.enabled()) {
Level minLevel =
Level.intToLevel(Math.min(logToFileOpt.logLevel().toInt(), logLevel.toInt()));
loggerSetup.setupFileAppender(minLevel, logRoot, logPrefix);
}
return loggerSetup.setupConsoleAppender(logLevel);
}

View File

@ -115,14 +115,14 @@ public final class LogbackSetup extends LoggerSetup {
int port) {
Level targetLogLevel;
// Modify log level if we were asked to always log to a file.
// The receiver needs to get all logs (up to `trace`) so as to be able to log all verbose messages.
// The receiver needs to get all logs (up to `trace`) to be able to log all verbose messages.
if (logToFileEnabled()) {
int min = Math.min(Level.TRACE.toInt(), config.logToFile().logLevel().toInt());
int min = Math.min(logLevel.toInt(), config.logToFile().logLevel().toInt());
targetLogLevel = Level.intToLevel(min);
} else {
targetLogLevel = logLevel;
}
LoggerAndContext env = contextInit(targetLogLevel, config, !logToFileEnabled());
LoggerAndContext env = contextInit(targetLogLevel, config, true);
org.enso.logger.config.SocketAppender appenderConfig = config.getSocketAppender();

View File

@ -26,7 +26,17 @@ public class LoggingServiceManager {
throw new LoggingServiceAlreadySetup();
} else {
if (config.appenders().containsKey(config.appender())) {
currentLevel = config.logToFile().enabled() ? config.logToFile().logLevel() : logLevel;
if (config.logToFile().enabled()) {
String envSetLogLevel = System.getenv("ENSO_LOG_TO_FILE_LOG_LEVEL");
if (envSetLogLevel != null) {
currentLevel = config.logToFile().logLevel();
} else {
int min = Math.min(config.logToFile().logLevel().toInt(), logLevel.toInt());
currentLevel = Level.intToLevel(min);
}
} else {
currentLevel = logLevel;
}
return Future.apply(
() -> {
var server = LoggingServiceFactory.get().localServerFor(port);

View File

@ -64,7 +64,8 @@ logging-service {
max-file-size = "100MB"
max-history = 30
max-total-size = "2GB"
}
},
immediate-flush = true
},
{
name = "sentry"