Snap app logging to a text file

I have a Ubuntu Server application that is installed in /opt/myapp. Within this directory the application runs as a services and writes to /opt/myapp/logs/app.log.

How do I replicate this behavior in a Snap?

Can I map a symbolic link from “/snap/myapp/current/” to “/opt/myapp”?

Right now if I run the application manually it is getting errors writing to “/snap/myapp/current/logs/app.log”. What do I need to change to allow this.

The /snap directory is the place where your readonly package is mounted, you can indeed not write there… your app can use /var/snap/<snapname>/current when running as a system service (daemon) or to ~/snap/<snapname>/current when launched by a user… if the /opt path is hard-coded and you can not easily change it in the code, you can use a layout to re-map it to one of the writable dirs from above