1

I have a Java Gradle application that logs correctly during development, but does not work correctly when it is distributed.

When I run the program in my IDE (IntelliJ if that is relevant) the logging is formatted correctly, however, when I run "./gradlew distZip" and use the distributed software on our production server it does not create a log file and looses the logging.properties configuration it should have.

The logger pulls input from my logging.properties into LogManager, creates a handler with a simple formatter (configured in logging.properties), and adds the handler to the logger:

LogManager.getLogManager().readConfiguration(
    new FileInputStream("./src/main/java/logging/logging.properties"));
FileHandler handler = new FileHandler("myLog.log", FILE_SIZE, 4, true);
handler.setFormatter(new SimpleFormatter());
logger.addHandler(handler);

When I run this in IntelliJ I get a set of output files: myLog.log.x and log entries in those files match the properties I created:

[2022-07-12 09:26:32] [INFO] APPLICATION: Setting up application 
[2022-07-12 09:26:32] [INFO] Starting server on port: 8080
[2022-07-12 09:26:32] [INFO] Updating data from API 
...

When I run the bat file from the distribution it logs to the terminal and gives an IO error:

Jul 12, 2022 12:53:09 PM logging.ApplicationLogger getLogger
SEVERE: .\src\main\java\logging\logging.properties (The system cannot find the path 
specified)

I think this makes sense, since the distributed bat file doesn't know about the development file structure. What I don't know, is how to compensate for whatever "./gradlew distZip" does to the file structure. I tried adding the logging.properties file to the distribution as an additional file, but that didn't work.

How do I reference my logging.properties file so that it is found by my distribution?

1 Answer 1

0

The file is referenced relatively from the location of the .bat file in the distribution. For example, my .bat file is in the bin folder of my distribution. I added the logging.properties file to the distribution in the bin folder so I could reference it correctly.

With logging.properties in the bin directory I could simply change the reference to:

LogManager.getLogManager().readConfiguration(
new FileInputStream("./logging.properties"));

and it references correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.