Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why not auto-append the monolog channel as hashtag? #11

Closed
pnoeric opened this issue Jul 18, 2019 · 2 comments
Closed

Why not auto-append the monolog channel as hashtag? #11

pnoeric opened this issue Jul 18, 2019 · 2 comments

Comments

@pnoeric
Copy link

pnoeric commented Jul 18, 2019

Like the title says ;-) channels already exist in monolog to break log messages into various segments - billing, security, main, etc.

I wrote a custom processor to add '#' plus the channel name to my mesages that get sent to Stackify, so I can search the logs easily using y'alls nice hashtag feature. But it really should just be a part of this handler, no?

This is my very simple processor BTW


// set up Monolog
use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;
use Stackify\Log\Transport\ExecTransport;

$stackify_transport = new ExecTransport( '--my api key--' );
$handler_stackify   = new StackifyHandler( 'Main site', 'Production', $stackify_transport );

// Now create the main logger and tell it where to send the messages
$log = new Logger( 'billing' );

// add hashtag for stackify
$log->pushProcessor( function ( $record ) {
	// https://github.com/Seldaek/monolog/blob/master/doc/message-structure.md
	$record['message'] .= ' #billing';

	return $record;
} );

$log->pushHandler( $handler_stackify );

@paul-hendrick
Copy link

Using a custom processor to modify $record['message'] gets the job done, but it defies Monolog's convention somewhat, and would be less feasible in Monolog v3, where the property is read-only:

What would be ideal is if the handler could take in the channel and extra fields of Monolog\LogRecord, although I'm not sure if the model on Stackify's side has anywhere for this to go

@homiedopie
Copy link
Contributor

homiedopie commented Feb 5, 2024

Hi @pnoeric @paul-hendrick - This feature is now released for Monolog V3. You may need to add new arguments to include channel and extra in context for this to work.

stackify/stackify-log-monolog?tab=readme-ov-file#handler-level-option

@pnoeric - What version of Monolog are you using? If you are using v2, please let me know so I can add it as a new release and will let you know

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

No branches or pull requests

3 participants