Missing permission for nextcloud.log but log actually written?

Nextcloud version (eg, 20.0.5): 27.1.4snap1
Operating system and version (eg, Ubuntu 20.04): Ubuntu 22.04
Apache or nginx version (eg, Apache 2.4.25): 2.4
PHP version (eg, 7.4): 8.1

The issue you are facing:

The logs /var/snap/nextcloud/current/logs/php_errors.log shows the error:

[23-Jan-2024 22:19:32 UTC] {"reqId":"xxx","level":3,"time":"2024-01-23T22:19:32+00:00","remoteAddr":"192.168.x.y","user":"--","app":"PHP","method":"GET","url":"/index.php/login","**message":"fopen(/media/nextcloud/data/nextcloud.log): Failed to open stream: Permission denied at /snap/nextcloud/39212/htdocs/lib/private/Log/File.php#84**","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","version":"27.1.4.1","data":{"app":"PHP"}}

however the file /media/nextcloud/data/nextcloud.log is present and written regularly:

{"reqId":"xxx","level":0,"time":"2024-01-27T22:40:07+00:00","remoteAddr":"","user":"--","app":"cron","method":"","url":"--","message":"CLI cron call has selected job with ID 15226","userAgent":"--","version":"27.1.4.1","data":{"app":"cron"}}

Is this the first time you’ve seen this error? (Y/N): yes, I never had to check error logs before (for other reasons) so I never noticed.

Steps to replicate it:

I’m not sure, but the snap runs as root and /media/nextcloud is a ZFS dataset owned by root:

drwxrws--- 11 root root 17 Jan 27 22:31 data
# ls -l /media/
drwxr-xr-x 3 root root 3 Aug 29 2019 nextcloud

The snap otherwise works, I can upload and browse files.

The output of your Nextcloud log in Admin > Logging:

Infodav2024-01-27T23:14:55+0100
Pruned 0 calendar sync tokens and 0 address book sync tokens
Infocalendar2024-01-27T23:14:55+0100
Found and deleted 0 outdated booking confirmations.
Infono app in context2024-01-27T22:59:51+0100
Could not find updater directory /media/nextcloud/data/updater-ocubu6eg3rbb/backups - cleanup step not needed

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/snap/nextcloud/current/htdocs/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/snap/nextcloud/current/nextcloud/extra-apps',
      'url' => '/extra-apps',
      'writable' => true,
    ),
  ),
  'supportedDatabases' => 
  array (
    0 => 'mysql',
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/tmp/sockets/redis.sock',
    'port' => 0,
  ),
  'trusted_domains' => 
  array (
    0 => 'nextcloud.y.net',
    1 => '192.168.x.y',
  ),
  'datadirectory' => '/media/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '27.1.4.1',
  'installed' => true,
  'instanceid' => 'xxx',
  'loglevel' => 0,
  'theme' => '',
  'trusted_proxies' => 
  array (
    0 => '172.18.0.2',
  ),
  'maintenance' => false,
  'overwriteprotocol' => 'https',
  'overwritehost' => 'nextcloud.y.net',
  'overwrite.cli.url' => 'https://nextcloud.y.net',
);