Skip to content

Pass context to the logger class override hook#78

Open
dd32 wants to merge 1 commit intohumanmade:masterfrom
dd32:patch-3
Open

Pass context to the logger class override hook#78
dd32 wants to merge 1 commit intohumanmade:masterfrom
dd32:patch-3

Conversation

@dd32
Copy link
Copy Markdown
Contributor

@dd32 dd32 commented Apr 9, 2025

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

Prior to #72 7af82ca 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..

When extending the Logger class, information about the Database connection is likely to be required by the Logger.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant