Home > Back-end >  Spring application war - Google App Engine - How to specify Log location, profile, environment varia
Spring application war - Google App Engine - How to specify Log location, profile, environment varia

Time:09-17

I have a spring boot application bundled as war file , and able to push to App Engine

But I am getting problems starting app (I suspect there could be an issue with DB too...but couldnt remember where I saw...a nightmare)

java.lang.RuntimeException: java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Failed to create parent directories for [/base/data/home/apps/e~pemy/20210716t001812.436581063072799646/logs/pynew.log] ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - openFile(logs/pynew.log,true) call failed. java.io.FileNotFoundException: logs/pynew.log (No such file or directory)

I am using the below properties in my application props

> logging.file.path=logs
> logging.file.name=${logging.file.path}/pynew.log

I am finding it very hard to include google specific dependencies and properties , and making a mess of my project...created app.yaml, web-inf>> appengine-web xml, logging.properties (not sure why but added as told in a tutorial)

Question: How can I create parent directory or link to cloud storage folder etc?

I also want to specify a profile and I see I can do it in yaml file. Is this used only

env_variables:
    JAVA_USER_OPTS: '-Dspring.profiles.active=prod'

But I would like to know how to connect to Cloud SQL

spring.datasource.url=jdbc:mysql:///mydb?cloudSqlInstance=myapp:europe-west2:dBinstancename&socketFactory=com.google.cloud.sql.mysql.SocketFactory
spring.datasource.username=${dbuser}
spring.datasource.password=ENC(${dbencpwd})

spring.cloud.gcp.sql.database-name=mydb
spring.cloud.gcp.sql.instance-connection-name=myapp:europe-west2:dBinstancename

It is so confusing that I keep forgetting which connection needs password and which wont. and keep breaking my local

Question Assuming that I need to supply credentials, How can I supply - ${dbuser}

CodePudding user response:

I used the default spring logger with logback-spring.xml for all my development, and this is not working on AppEngine

So I followed https://cloud.google.com/logging/docs/setup/java and added logback.xml and the dependency

 implementation 'com.google.cloud:google-cloud-logging-logback:0.121.3-alpha'
  • Related