Backend Development 2 min read

Laravel Log Quick Reference and SQL Query Logging Guide

This article provides a concise Laravel Log quick reference, detailing the seven RFC‑5424 log levels, usage examples, how to retrieve the Monolog instance, add listeners, and enable and fetch SQL query logs, followed by motivational reflections on perseverance and growth.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Laravel Log Quick Reference and SQL Query Logging Guide

Log is used in Laravel to manage error levels.

// Logger provides 7 levels defined in RFC 5424 standard:
debug, info, notice, warning, error, critical, and alert.
Log::info('info');
Log::info('info', array('context'=>'additional info'));
Log::error('error');
Log::warning('warning');
// Get Monolog instance
Log::getMonolog();
// Add listener
Log::listen(function ($level, $message, $context) {});

To record SQL query statements, enable the query log and retrieve the executed queries:

// Enable log
DB::connection()->enableQueryLog();
// Get executed queries array
DB::getQueryLog();

Helping others helps yourself; technology shapes life, and knowledge changes destiny.

Life is not always smooth, time is not spotless, and success does not come instantly; overcoming loneliness, yesterday, desert, hardships, and mental swamps leads to growth, wisdom, and fearlessness.

BackendSQLloggingPHPLaravelmonolog
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.