CakePHP4 Logging

I used to use $this->log() to log strings, arrays or objects to the debug.log file for inspection with developing and debugging. With CakePHP4, I’m replacing this with Log::debug(). However, if I try to log anything other than a string it throws a strict type error. What’s the recommend approach for logging an array or possibly on object to the debug.log file?

Use Debugger::exportVar

use Cake\Error\Debugger;

$data = [
  'a' => [....],
Log::debug(Debugger::exportVar($data, 6));

It shows the same output as if you do debug() on cli

1 Like

I think this is the solution

 private function convertToLogMessage(array $msg): string
        return implode(', ', $msg);