Created
November 6, 2024 21:14
Automatically convert log content to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace ProcessWire; | |
use stdClass; | |
/** | |
* Automatically converts array or object log values to JSON | |
* | |
* When logging, use an array or JSON serializable object such as a stdClass as the message | |
* If the message is a string, doesn't touch it | |
*/ | |
wire()->addHookBefore("WireLog::save",function (HookEvent $e) { | |
$text = $e->arguments('text'); | |
(is_array($text) || $text instanceof stdClass) && $e->arguments('text', json_encode($text)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment