Skip to content

Instantly share code, notes, and snippets.

@SkyLundy
Created November 6, 2024 21:14
Automatically convert log content to JSON
<?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