diff --git a/core/constant_inc.php b/core/constant_inc.php index 91bcabc038..a1deb94ea4 100644 --- a/core/constant_inc.php +++ b/core/constant_inc.php @@ -259,6 +259,7 @@ define( 'ERROR_SPAM_SUSPECTED', 27 ); define( 'ERROR_FIELD_TOO_LONG', 28 ); define( 'ERROR_INVALID_FIELD_VALUE', 29 ); +define( 'ERROR_LOGFILE_NOT_WRITABLE', 30 ); # ERROR_CONFIG_* define( 'ERROR_CONFIG_OPT_NOT_FOUND', 100 ); diff --git a/core/logging_api.php b/core/logging_api.php index c5736d51a6..73c0d5a577 100644 --- a/core/logging_api.php +++ b/core/logging_api.php @@ -106,7 +106,26 @@ function log_event( $p_level, $p_msg ) { case 'none': break; case 'file': - error_log( $t_php_event . PHP_EOL, 3, $t_modifiers ); + if( isset( $t_modifiers ) ) { + # Detect if the log file is writable; if not, issue a one-time warning + static $s_log_writable = null; + if( $s_log_writable === null ) { + $s_log_writable = is_writable( $t_modifiers ); + if( !$s_log_writable ) { + # Display warning message and write it in PHP system log as well. + # Note: to ensure the error is shown regardless of $g_display_error settings, + # we manually set the message and log it with error_log_delayed(), which will + # cause it to be displayed at page bottom. + error_parameters( $t_modifiers ); + $t_message = error_string( ERROR_LOGFILE_NOT_WRITABLE ); + error_log_delayed( $t_message ); + error_log( 'MantisBT - ' . htmlspecialchars_decode( $t_message ) ); + } + } + if( $s_log_writable ) { + error_log( $t_php_event . PHP_EOL, 3, $t_modifiers ); + } + } break; case 'page': global $g_log_events; diff --git a/lang/strings_english.txt b/lang/strings_english.txt index c22c19ca8f..efb258f2a8 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -1770,6 +1770,7 @@ $MANTIS_ERROR[ERROR_BUG_CONFLICTING_EDIT] = 'This issue has been updated by anot $MANTIS_ERROR[ERROR_SPAM_SUSPECTED] = 'You have reached the allowed activity limit of %d events within the last %d seconds; your action has been blocked to avoid spam, please try again later.'; $MANTIS_ERROR[ERROR_FIELD_TOO_LONG] = 'Field "%1$s" must be shorter or equal to %2$d characters long.'; $MANTIS_ERROR[ERROR_API_TOKEN_NAME_NOT_UNIQUE] = 'API token name "%s" is already being used. Please go back and select another one.'; +$MANTIS_ERROR[ERROR_LOGFILE_NOT_WRITABLE] = 'The file specified in $g_log_destination "%s" is not writable.'; # dropzone.js - placeholders format is defined by the library $s_dropzone_default_message = 'Drop files here to upload (or click)';