0

I'm trying to do some Logging modification on My Standard AppEngine Java 11 app using a logging.properties file, My app is a Jetty web-server which I run by adding the following entry-point to my app.yaml file

runtime: java11
entrypoint: 'java -cp "*" com.jettymain.Main webapp.war'

Now Google documentation here suggests that in order to use logging.properties. The path to the configuration file must be provided to your application as a system property: -Djava.util.logging.config.file=/path/to/logging.properties

I have tried setting that in the code, first thing in the com.jettymain.Main class which starts the Jetty embedded web-server by doing the following

System.setProperty("java.util.logging.config.file", "WEB-INF/logging.properties")

But that didn't work, modifying the entry-point in app.yaml did make the web-server load those configurations but it was failing to load the Google cloud logging handler class com.google.cloud.logging.LoggingHandler, which I need to write those logs to Google Stackdriver, I have the Google cloud logging dependency added to both my app and the web-server but that didn't help.

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-logging</artifactId>
  <version>3.0.1</version>
</dependency>

modified entry-pint

runtime: java11
entrypoint: 'java -cp "*" com.jettymain.Main webapp.war -Djava.util.logging.config.file=WEB-INF/logging.properties'

logging.properties file, it is the sample file which can be found here plus few extra things

# To use this configuration, add to system properties : -Djava.util.logging.config.file="/path/to/file"
.level = INFO

# it is recommended that io.grpc and sun.net logging level is kept at INFO level,
# as both these packages are used by Cloud internals and can result in verbose / initialization problems.
io.grpc.netty.level=INFO
sun.net.level=INFO

handlers=com.google.cloud.logging.LoggingHandler
# default : java.log
com.google.cloud.logging.LoggingHandler.log=custom_log

# default : INFO
com.google.cloud.logging.LoggingHandler.level=FINE

# default : ERROR
com.google.cloud.logging.LoggingHandler.flushLevel=EMERGENCY

# default : auto-detected, fallback "global"
com.google.cloud.logging.LoggingHandler.resourceType=container

# custom formatter
com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s

# Level for all logs coming from GWT client (can't filter by specific classes on client)
com.google.gwt.logging.server.RemoteLoggingServiceUtil.level = WARNING
com.beoui.geocell.level=WARNING
montss
  • 444
  • 9
  • 17
  • I assume you are using java.util.logging handler for setting up Cloud Logging for Java and not the Cloud logging library for Java directly? – Priyashree Bhadra Aug 26 '21 at 06:39

1 Answers1

-1

Get the System.setProperty into any method. It can be the main method also. I think the problem is "the logging.properties must go in WEB-INF/classes directory" as per this link and not WEB-INF/ directory as mentioned in your code.

System.setProperty("java.util.logging.config.file", "WEB-INF/classes/logging.properties")
Priyashree Bhadra
  • 2,257
  • 1
  • 15
  • Not sure where to execute this command, in Appengine Standard environment app.yaml entrypoint seems the only place to do similar thing, and I tried that as I mentioned but it didn't work. – montss Aug 30 '21 at 08:48
  • Execute the command I posted in the answer in your terminal if you are a Mac user or in Command Line if you are a Windows User. You can use Cloud Shell too. Specify your MainClass and provide the correct path. – Priyashree Bhadra Aug 30 '21 at 08:57
  • I want to run my app on a Deployed standard Appengine environment in the could, so I don't have access to any terminal, I don't have any problem with the app or the logs locally. – montss Aug 30 '21 at 09:38
  • Okay I get it now. As mentioned in the Google docs "The path to the configuration file must be provided to your application as a system property: -Djava.util.logging.config.file=/path/to/logging.properties". You are translating this path/to/ logging.properties to be " WEB-INF/logging.properties". Why do you think it should be set as WEB-INF/logging.properties? – Priyashree Bhadra Aug 30 '21 at 15:58
  • Because I have my logging.properties file in that directory. The question is how to do the "The path to the configuration file must be provided to your application as a system property". – montss Aug 31 '21 at 12:02
  • Just get the System.setProperty into any method. It can be the main method also. I think the problem is "the logging.properties must go in WEB-INF/classes directory" as per this [link](https://stackoverflow.com/a/14361928/15803365) and not WEB-INF/ directory as mentioned in your code. – Priyashree Bhadra Aug 31 '21 at 12:38
  • @montss Did you try setting System.setProperty in your main method like this System.setProperty("java.util.logging.config.file", "WEB-INF/classes/logging.properties")? Please let me know if this resolved your issue. – Priyashree Bhadra Sep 01 '21 at 14:39