牛骨文教育服务平台(让学习变的简单)

日志

Laravel 日志工具在强大的 Monolog 函数库上提供一层简单的功能。Laravel 默认为应用程序建立每天的日志文件在 storage/logs 目录。你可以像这样把信息写到日志:

Log::info("This is some useful information.");

Log::warning("Something could be going wrong.");

Log::error("Something is really going wrong.");

日志工具提供定义在 RFC 5424 的七个级别:debug、info、notice、warning、error、critical 和 alert。

也可以传入上下文相关的数据数组到日志方法里:

Log::info("Log message", ["context" => "Other helpful information"]);

Monolog 有很多其他的处理方法可以用在日志上。如有需要,你可以取用 Laravel 底层使用的 Monolog 实例:

$monolog = Log::getMonolog();

你也可以注册事件来捕捉所有传到日志的消息:

注册日志事件监听器

Log::listen(function($level, $message, $context)
{
    //
});