Cavalcade-Runner icon indicating copy to clipboard operation
Cavalcade-Runner copied to clipboard

Pass context to the logger class override hook

Open dd32 opened this issue 8 months ago • 0 comments

When extending the Logger class, information about the Database connection is likely to be required by the Logger.

Prior to #72 7af82ca60bae6b4f589370a516c3c378e95a1cc9 the following code worked:

$runner->hooks->register( 'Runner.check_workers.logger', function( $logger ) {
	return new MyLogger( $logger->db, $logger->table_prefix );
} );

Now code similar to this is required:

$runner->hooks->register( 'Runner.connect_to_db.connected', function( $db ) {
	$GLOBALS['_cavalcade_db'] = $db;
} );
$runner->hooks->register( 'Runner.bootstrap.table_prefix', function( $table_prefix ) {
	$GLOBALS['_cavalcade_table_prefix'] = $table_prefix;

	return $table_prefix;
} );
$runner->hooks->register( 'Runner.check_workers.logger', function( $logger ) {
	return new MyLogger(
		$GLOBALS['_cavalcade_db'],
		$GLOBALS['_cavalcade_table_prefix']
	);
} );

Alternatively, these could be made public, but just passing it as an extra arg is probably enough..

dd32 avatar Apr 09 '25 03:04 dd32