Skip to content

Adjust logback outfile file upon startup #4823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions runner/client/src/mill/runner/client/MillClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
public class MillClientMain {
public static void main(String[] args) throws Exception {

if (System.getProperty("mill.log.file") == null)
System.setProperty("mill.log.file", OutFiles.out + "/mill.log");

boolean runNoServer = false;
if (args.length > 0) {
String firstArg = args[0];
Expand Down
2 changes: 1 addition & 1 deletion runner/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<configuration debug="false" scan="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>out/mill.log</file>
<file>${mill.log.file:-out/mill.log}</file>
<encoder>
<pattern>%date %level [%thread] %logger{36} %msg%n</pattern>
</encoder>
Expand Down
12 changes: 12 additions & 0 deletions runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ object MillMain {
}

def main(args: Array[String]): Unit = SystemStreams.withTopLevelSystemStreamProxy {
adjustLogbackOutputFile()
val initialSystemStreams = SystemStreams.original
// setup streams
val (runnerStreams, cleanupStreams, bspLog) =
Expand Down Expand Up @@ -432,6 +433,17 @@ object MillMain {
for ((k, v) <- desiredProps) System.setProperty(k, v)
}

// Logback is set up via a logback.xml file in resources, so that if an app
// tries to log via slf4j, its logs will go somewhere. We need to tell logback
// where to write its output file. The out directory might not be "out/", so we
// set a Java property, used in logback.xml and then read by logback, so that
// the logs go to a file under the actual out directory.
// This method should be called early on in Mill processes, not to miss any
// slf4j use.
def adjustLogbackOutputFile(): Unit =
if (!sys.props.contains("mill.log.file"))
sys.props("mill.log.file") = s"${OutFiles.out}/mill.log"

def withOutLock[T](
noBuildLock: Boolean,
noWaitForBuildLock: Boolean,
Expand Down
2 changes: 2 additions & 0 deletions runner/src/mill/runner/MillServerMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ object MillServerMain {
}
)

MillMain.adjustLogbackOutputFile()

val acceptTimeoutMillis =
Try(System.getProperty("mill.server_timeout").toInt).getOrElse(30 * 60 * 1000) // 30 minutes

Expand Down