payara / Payara

Payara Server is an open source middleware platform that supports reliable and secure deployments of Java EE (Jakarta EE) and MicroProfile applications in any environment: on premise, in the cloud or hybrid.
http://www.payara.fish
Other
886 stars 307 forks source link

LogToFile doesn't work since Payara-Micro v5.2020.4 with uber jar (most probably due to [FISH-35]) /FISH-450 #4892

Closed AndrewG10i closed 3 years ago

AndrewG10i commented 4 years ago

Description


--logToFile option doesn't work when used with Uber Jar, it always returns:

Sep 17, 2020 8:31:12 PM fish.payara.micro.impl.PayaraMicroImpl resetLogging
WARNING: logToFile command line option ignored as a logging.properties file has been provided

As result - no log file is created as well.

Expected Outcome

Log file should be created according to the provided param --logToFile

Current Outcome

No log file created and WARNING log message always printed to console.

Steps for reproducing the issue

  1. Download sample project e.g.: https://github.com/AndrewG10i/JsfSampleApp
  2. Unzip JsfSampleApp-trunk.zip
  3. Execute cd JsfSampleApp-trunk && mvn package
  4. Build uber jar: java -jar payara-micro-5.2021.7.jar --deploy JsfSampleApp-trunk\target\jsfDebug-1.0.war; --outputUberJar jsfSampleApp.jar
  5. Launch it: java -jar jsfSampleApp.jar --logToFile D:\server.log -> as result no log file D:\server.log created and also while launching the server you can see the following output in console: WARNING: logToFile command line option ignored as a logging.properties file has been provided (almost the most 1st line in console output)
  6. But if you comment out #payaramicro.logPropertiesFile=false line inside jsfSampleApp.jar\MICRO-INF\deploy\payaramicro.properties and launch it again in the same way: java -jar jsfSampleApp.jar --logToFile D:\server.log -> you can see a log file successfully created.

Investigation of the root cause

  1. I have conducted investigation and it seems that the root cause is due to these lines added in 5.2020.4 (you need to switch to "Files changed" tab and refresh it several times in order to get to the desired diff).

So you can see the code added in 5.2020.4 (PayaraMicroImpl.java): image

  1. The issue that in case of uber jar USER_PROPS_FILE ("MICRO-INF/deploy/payaramicro.properties") always contains value like: payaramicro.logPropertiesFile=false|true

  2. As result if (userLogPropertiesFileStr != null && !userLogPropertiesFileStr.trim().isEmpty()) always gives true

I was able to confirm this theory simply by renaming payaramicro.logPropertiesFile=false into payaramicro.logPropertiesFile1=false in USER_PROPS_FILE inside uber jar, after that logging to file started working fine again.

It would be very nice if you could include the fix for this issue in the next release.

Thank you!

khasunuma commented 4 years ago

Hi @Andrew-Gr, thank you for detailed investigation. I've reproduced the issue easily and raised internal issue FISH-450.

rdebusscher commented 3 years ago

Hi @AndrewG10i

Is this still an issue? we tried with

java -jar target/demo-microbundle.jar --logtofile rudy.log

And log file is created as expected.

Thx Rudy

AndrewG10i commented 3 years ago

Hello @rdebusscher,

yes, I do confirm that issue still present with Payara Micro 5.2021.7. Description provided in the initial post still valid, issue reproduces with the uber jar. We still use the same approach: by commenting out payaramicro.logPropertiesFile prop inside resulting uber jar (MICRO-INF/deploy/payaramicro.properties) - helps to resolve the issue.

Let me know if you need us to provide a reproducer.

Thank you!

rdebusscher commented 3 years ago

Hi @AndrewG10i

This is the usecase we have tested.

curl -O -J 'https://start.microprofile.io/api/project?supportedServer=PAYARA_MICRO&selectedSpecs=CONFIG'
unzip demo.zip
mvn clean package
java -jar target/demo-microbundle.jar --logtofile rudy.log

Please let us known how you create and use the uberjar of Payara Micro.

Rudy

AndrewG10i commented 3 years ago

Hi @rdebusscher,

I see now what you mean. I am referring to a different approach, sorry for not clarifying it in my original post. I have just corrected it and extended initial post with the steps on reproducing the issue. Sorry again for wasting your time while trying to figure out what did I mean...!

Thank you!

rdebusscher commented 3 years ago

Hi @AndrewG10i

You are correct, using the uberJar creation facilities of Payara Micro itself, results in the problem you have described. But not when you are using the Payara Micro Maven Plugin.

By adding

         <plugin>
            <groupId>fish.payara.maven.plugins</groupId>
            <artifactId>payara-micro-maven-plugin</artifactId>
            <version>1.0.5</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>bundle</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <payaraVersion>5.2021.7</payaraVersion>
            </configuration>
          </plugin>

You also have an uber jar and it is much easier

For Payara Enterprise Customers we can consider fixing this, with low priority as there is a workaround, but we decided not to fix this ourselves for the community. You are encouraged to submit a PR yourself where the changed code gives priority to the --logtofile option over the embedded or specified logging properties file.

Rudy