A user (Piwigo 16.4.0, PHP 8.5.9, MariaDB 12.3.2, SELinux enabled) got a fatal error and lost access to the admin panel because _data/logs was not writable (SELinux context issue on their server). The exact message was:
Fatal error: Uncaught RuntimeException: The file could not be written to. Check that appropriate permissions have been set.
What I found in the code
In include/Logger.class.php, Logger::open() throws a RuntimeException when the target log file/directory isn't writable, and write() calls open() on every log call without catching anything.
In include/common.inc.php, $logger = new Logger(...) is not wrapped in a try/catch — unlike pwg_db_connect() just above it, which is.
No global set_exception_handler() is registered in common.inc.php to turn an uncaught exception into a graceful error page.
The default log level (include/config_default.inc.php) is DEBUG, so logging is active by default, and $logger->info(...)/debug(...) calls happen fairly early/often (e.g. in functions.inc.php).
Effect
If the log directory becomes unwritable for any reason (permissions, SELinux context, full disk, read-only filesystem, etc.), the first log call of the request throws an uncaught exception and the whole page dies with a raw PHP fatal error — including the admin panel, which is precisely where one would go to diagnose or fix the issue.
Possible direction (just a suggestion, happy to be told this was already considered)
Would it make sense for logging failures to degrade gracefully instead of being fatal — e.g. catching the exception in Logger::log()/write() and silently disabling logging for the rest of the request (maybe with a one-time trigger_error(E_USER_WARNING)) rather than letting it propagate? That way a logging-only problem wouldn't take down the whole application.
Happy to provide more details or test a patch if useful. Thanks for maintaining Piwigo!
Hello,
While helping a user on the forum ([fr.piwigo.org/forum/viewtopic.php?pid=245721#p245721](https://fr.piwigo.org/forum/viewtopic.php?pid=245721#p245721)), I noticed a fragility in the logging system that I wanted to report, in case it's worth a small hardening.
**Context from the forum thread**
A user (Piwigo 16.4.0, PHP 8.5.9, MariaDB 12.3.2, SELinux enabled) got a fatal error and lost access to the admin panel because `_data/logs` was not writable (SELinux context issue on their server). The exact message was:
```
Fatal error: Uncaught RuntimeException: The file could not be written to. Check that appropriate permissions have been set.
```
**What I found in the code**
- In `include/Logger.class.php`, `Logger::open()` throws a `RuntimeException` when the target log file/directory isn't writable, and `write()` calls `open()` on every log call without catching anything.
- In `include/common.inc.php`, `$logger = new Logger(...)` is not wrapped in a try/catch — unlike `pwg_db_connect()` just above it, which is.
- No global `set_exception_handler()` is registered in `common.inc.php` to turn an uncaught exception into a graceful error page.
- The default log level (`include/config_default.inc.php`) is `DEBUG`, so logging is active by default, and `$logger->info(...)`/`debug(...)` calls happen fairly early/often (e.g. in `functions.inc.php`).
**Effect**
If the log directory becomes unwritable for any reason (permissions, SELinux context, full disk, read-only filesystem, etc.), the first log call of the request throws an uncaught exception and the whole page dies with a raw PHP fatal error — including the admin panel, which is precisely where one would go to diagnose or fix the issue.
**Possible direction (just a suggestion, happy to be told this was already considered)**
Would it make sense for logging failures to degrade gracefully instead of being fatal — e.g. catching the exception in `Logger::log()`/`write()` and silently disabling logging for the rest of the request (maybe with a one-time `trigger_error(E_USER_WARNING)`) rather than letting it propagate? That way a logging-only problem wouldn't take down the whole application.
Happy to provide more details or test a patch if useful. Thanks for maintaining Piwigo!
<!-- github-sync-id:5352154721 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Hello,
While helping a user on the forum (fr.piwigo.org/forum/viewtopic.php?pid=245721#p245721), I noticed a fragility in the logging system that I wanted to report, in case it's worth a small hardening.
Context from the forum thread
A user (Piwigo 16.4.0, PHP 8.5.9, MariaDB 12.3.2, SELinux enabled) got a fatal error and lost access to the admin panel because
_data/logswas not writable (SELinux context issue on their server). The exact message was:What I found in the code
include/Logger.class.php,Logger::open()throws aRuntimeExceptionwhen the target log file/directory isn't writable, andwrite()callsopen()on every log call without catching anything.include/common.inc.php,$logger = new Logger(...)is not wrapped in a try/catch — unlikepwg_db_connect()just above it, which is.set_exception_handler()is registered incommon.inc.phpto turn an uncaught exception into a graceful error page.include/config_default.inc.php) isDEBUG, so logging is active by default, and$logger->info(...)/debug(...)calls happen fairly early/often (e.g. infunctions.inc.php).Effect
If the log directory becomes unwritable for any reason (permissions, SELinux context, full disk, read-only filesystem, etc.), the first log call of the request throws an uncaught exception and the whole page dies with a raw PHP fatal error — including the admin panel, which is precisely where one would go to diagnose or fix the issue.
Possible direction (just a suggestion, happy to be told this was already considered)
Would it make sense for logging failures to degrade gracefully instead of being fatal — e.g. catching the exception in
Logger::log()/write()and silently disabling logging for the rest of the request (maybe with a one-timetrigger_error(E_USER_WARNING)) rather than letting it propagate? That way a logging-only problem wouldn't take down the whole application.Happy to provide more details or test a patch if useful. Thanks for maintaining Piwigo!