Messages Log in custom Module – Drupal 8

May times when to stuck due async call in custom code, below code will be very useful to know what data in a variable or array.

Code to add log message in Drupal 8.

// Logs a notice

// Logs an error


Code to print array variable.

// Logs a notice
\Drupal::logger('my_module')->notice('<pre><code>'. print_r( $message, true).'</code></pre>');