Andrew Fletcher published: 26 August 2021 1 minute read
In drupal 9 for logging you can use logger service to log array data in some readable format, by adding html code and print_r to array.
\Drupal::logger('my_module')->warning('<pre><code>' . print_r($responseObj, TRUE) . '</code></pre>');
my_module is type of log message, warning is severity method you call and $responseObj is array you need to put to log file to have some formatting. Other options you can use include:
emergency($message, $context) alert($message, $context) critical($message, $context) error($message, $context) warning($message, $context) notice($message, $context) info($message, $context) debug($message, $context)
Can be used as follows:
\Drupal::logger('my_module')->notice($message);
\Drupal::logger('my_module')->error($message);