`sonar.log.maxFiles` is the maximum number of files to keep. This property is ignored if `sonar.log.rollingPolicy=none`.
-#### **Wrapper Config**
-
-If Sonarqube was started using the SonarQube wrapper (for example, by using the provided start and stop scripts), the log rotation of the main Process (sonar.log) needs to be defined in the `wrapper.conf`.
-By Default, the wrapper will rotate the `sonar.log` file each day if there is new content to be logged.
-
-The log rotation in the wrapper can be fine-tuned with the following properties:
-
-* **`wrapper.logfile.maxsize=value[m for mb, k for kb]`**
-* **`wrapper.logfile.maxfiles=value`**
-* **`wrapper.logfile.rollmode=DATE|SIZE`**
-
-`wrapper.logfile.maxsize` and `wrapper.logfile.maxfiles` are only considered if `wrapper.logfile.rollmode` is set to `SIZE`.
-For `wrapper.logfile.rollmode=DATE` to work properly, the file defined with the property `wrapper.logfile` needs to include a "YYYYMMDD" Token.
-
### UI Access to Logs and Log Levels
The System Info page gives you the ability to download your instance's current log files (log files rotate on a regular basis), and to tune the log level via controls at the top of the page. Changes made here are temporary, and last only until the next time the instance is restarted, at which point the level will be reset to the more permanent value set in _$SONARQUBE-HOME/conf/sonar.properties_. Regardless, if you change your log level _from_ `INFO`, but sure to change it back as soon as is practical; log files can get very large very quickly at lower log levels.
helper.enableJulChangePropagation(ctx);
configureConsole(ctx);
- if (helper.isAllLogsToConsoleEnabled(appSettings.getProps()) || !appSettings.getProps().valueAsBoolean("sonar.wrapped", false)) {
- configureWithLogbackWritingToFile(ctx);
- } else {
- configureWithWrapperWritingToFile(ctx);
- }
+ configureWithLogbackWritingToFile(ctx);
+
helper.apply(
LogLevelConfig.newBuilder(helper.getRootLoggerName())
.rootLevelFor(ProcessId.APP)
startupLogger.addAppender(helper.newConsoleAppender(ctx, GOBBLER_PLAIN_CONSOLE, encoder));
}
- /**
- * SQ has been started by the wrapper (ie. with sonar.sh) therefor, APP's System.out (and System.err) are written to
- * sonar.log by the wrapper.
- */
- private void configureWithWrapperWritingToFile(LoggerContext ctx) {
- // configure all logs (ie. root logger) to be written to console with formatting
- // in practice, this will be only APP's own logs as logs from sub processes are written to LOGGER_GOBBLER and
- // LOGGER_GOBBLER is configured below to be detached from root
- // logs are written to the console because we want them to be in sonar.log and the wrapper will write any log
- // from APP's System.out and System.err to sonar.log
- Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
- Encoder<ILoggingEvent> encoder = helper.createEncoder(appSettings.getProps(), rootLoggerConfig, ctx);
- rootLogger.addAppender(createAppConsoleAppender(ctx, encoder));
-
- // in regular configuration, sub processes are not copying their logs to their System.out, so, the only logs to be
- // expected in LOGGER_GOBBLER are those before logback is setup in subprocesses or when JVM crashes
- // so, they must be printed to App's System.out as is (as they are already formatted) and the wrapper will write
- // them to sonar.log
- // logger is configured to be non additive as we don't want these logs written to sonar.log and duplicated in the
- // console with an incorrect formatting
- configureGobbler(ctx);
- }
-
/**
* Configure the logger to which logs from sub processes are written to
* (called {@link StreamGobbler#LOGGER_GOBBLER}) by {@link StreamGobbler},
new LogbackHelper().resetFromXml("/logback-test.xml");
}
- @Test
- public void no_writing_to_sonar_log_file_when_running_from_sonar_script() {
- emulateRunFromSonarScript();
-
- LoggerContext ctx = underTest.configure();
-
- ctx.getLoggerList().forEach(AppLoggingTest::verifyNoFileAppender);
- }
-
@Test
public void root_logger_only_writes_to_console_with_formatting_when_running_from_sonar_script() {
- emulateRunFromSonarScript();
-
LoggerContext ctx = underTest.configure();
Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
- ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) rootLogger.getAppender("APP_CONSOLE");
+ var consoleAppender = (ConsoleAppender<ILoggingEvent>) rootLogger.getAppender("APP_CONSOLE");
verifyAppFormattedLogEncoder(consoleAppender.getEncoder());
- assertThat(rootLogger.iteratorForAppenders()).toIterable().hasSize(1);
+ var rollingFileAppender = rootLogger.getAppender("file_sonar");
+ assertThat(rollingFileAppender).isNotNull();
+ assertThat(rootLogger.iteratorForAppenders()).toIterable().hasSize(2);
}
@Test
public void gobbler_logger_writes_to_console_without_formatting_when_running_from_sonar_script() {
- emulateRunFromSonarScript();
-
LoggerContext ctx = underTest.configure();
Logger gobblerLogger = ctx.getLogger(LOGGER_GOBBLER);
verifyGobblerConsoleAppender(gobblerLogger);
+
assertThat(gobblerLogger.iteratorForAppenders()).toIterable().hasSize(1);
}
assertThat(((LayoutWrappingEncoder)encoder).getLayout()).isInstanceOf(LogbackJsonLayout.class);
}
- private void emulateRunFromSonarScript() {
- settings.getProps().set("sonar.wrapped", "true");
- }
-
private void emulateRunFromCommandLine(boolean withAllLogsPrintedToConsole) {
if (withAllLogsPrintedToConsole) {
settings.getProps().set("sonar.log.console", "true");