8.5.x Drupal.php Drupal::logger($channel)
8.0.x Drupal.php Drupal::logger($channel)
8.1.x Drupal.php Drupal::logger($channel)
8.2.x Drupal.php Drupal::logger($channel)
8.3.x Drupal.php Drupal::logger($channel)
8.4.x Drupal.php Drupal::logger($channel)
8.6.x Drupal.php Drupal::logger($channel)

Returns a channel logger object.


string $channel: The name of the channel. Can be any string, but the general practice is to use the name of the subsystem calling this.

Return value

\Psr\Log\LoggerInterface The logger for this channel.


core/lib/Drupal.php, line 670
Contains \Drupal.


Static Service Container wrapper.


public static function logger($channel) {
  return static::getContainer()


sagar.w’s picture

// Logs a notice
// Logs an error

jdgp77’s picture

We have many logs:

Action must be taken immediately:

Critical conditions:

Detailed debug information:

System is unusable:

Runtime errors that do not require immediate action but should typically be logged and monitored:
Tipical errors, as when the page doesn't load

Interesting events:

Logs with an arbitrary level:
(Ex: When a module was installed)

Normal but significant events:
(Normals events, as cron execution)

Exceptional occurrences that are not errors:

You can see this logs in: /admin/reports/dblog

This is very importan, because you can report to others developers or admins, to many importants thinks in yours modules.

japo32’s picture

Also don't use t() for logger messages.

$logger->alert('Message from @module: @message.', [
  '@module' => $module,
  '@message' => $message,

The messages are stored untranslated and will be translated on runtime.