Skip to content

Instantly share code, notes, and snippets.

@vades
Last active May 21, 2019 06:14
Show Gist options
  • Save vades/7a2c13197ac5ac2ee5bdf3a301dbd2c8 to your computer and use it in GitHub Desktop.
Save vades/7a2c13197ac5ac2ee5bdf3a301dbd2c8 to your computer and use it in GitHub Desktop.
Laravel logging

Laravel logging

Laravel provides logging services that allow you to log errors, messages, events and uses Monolog, a powerful popular PHP logging library for all its logging needs.

Configuration

config/logging.php 

Log levels

  • emergency,
  • alert,
  • critical,
  • error,
  • warning,
  • notice,
  • info,
  • debug.

Namespace

Illuminate\Support\Facades\Log`

Writing log messages

  • Log::emergency('Log message comes here');
  • Log::alert('Log message comes here');
  • Log::critical('Log message comes here');
  • Log::error('Log message comes here');
  • Log::warning('Log message comes here');
  • Log::notice('Log message comes here');
  • Log::info('Log message comes here');
  • Log::debug('Log message comes here');

Passing an array of contextual data

Log::info('Log message with contextual data.', ['name' => $user->name]);

Output:

[2019-03-15 11:17:42] local.INFO: Log message with contextual data. {"name":"John doe"} 

Writing To Specific Channels

Log::channel('slack')->error('Something went wrong');

Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment