[GH-ISSUE #1081] undefined variable and array index not logging #438

Closed
opened 2026-03-04 02:15:01 +03:00 by kerem · 1 comment
Owner

Originally created by @sharazghouri on GitHub (Nov 16, 2017).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1081

spl_autoload_register( function ( $class ) {

	$path = dirname( __FILE__ ) . '\src\\' . $class . '.php';


	if ( file_exists( $path ) ) {
		require_once $path;
	}
} );

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\ErrorHandler;

// create a log channel

$log = new Logger( 'social media button ' );
$log->pushHandler( new StreamHandler(  dirname( __FILE__  ).'/error.log', Logger::WARNING ) );
ErrorHandler::register( $log );
/*----------- Fatal and Warning Error Handler -------*/
$arr = [0 , 1];
echo $arr[3]; 
//Notice  :  Undefined offset: 3 in  E:\xampp\htdocs\wp\wp-content\plugins\simple-social-buttons\classes\ssb-admin.php
//but not log in log file also 
trigger_error('df', E_USER_NOTICE);
//notice show but not log iin file 
Originally created by @sharazghouri on GitHub (Nov 16, 2017). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1081 ```php spl_autoload_register( function ( $class ) { $path = dirname( __FILE__ ) . '\src\\' . $class . '.php'; if ( file_exists( $path ) ) { require_once $path; } } ); use Monolog\Logger; use Monolog\Handler\StreamHandler; use Monolog\ErrorHandler; // create a log channel $log = new Logger( 'social media button ' ); $log->pushHandler( new StreamHandler( dirname( __FILE__ ).'/error.log', Logger::WARNING ) ); ErrorHandler::register( $log ); /*----------- Fatal and Warning Error Handler -------*/ $arr = [0 , 1]; echo $arr[3]; //Notice : Undefined offset: 3 in E:\xampp\htdocs\wp\wp-content\plugins\simple-social-buttons\classes\ssb-admin.php //but not log in log file also trigger_error('df', E_USER_NOTICE); //notice show but not log iin file ```
kerem 2026-03-04 02:15:01 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@snriud commented on GitHub (Nov 22, 2017):

ErrorHandler can only handle the runtime error, exception or fatal errors, but your 'undefined index' is notice level.

try trigger_error('en, error', E_USER_ERROR), you can get log record in error.log.

<!-- gh-comment-id:346277785 --> @snriud commented on GitHub (Nov 22, 2017): ErrorHandler can only handle the runtime error, exception or fatal errors, but your 'undefined index' is notice level. try trigger_error('en, error', E_USER_ERROR), you can get log record in error.log.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#438
No description provided.