0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Laravel】debug log をヘルパーから出力する方法

Posted at
info('インフォてすと');

debug('デバッグてすと');
laravel.php
[2024-11-25 20:21:44] testing.INFO: インフォてすと 

何故か表示されない :thinking:

原因

IDE でジャンプしてみると・・・

info() は、ちゃんと Hepler に繋がってた

# vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
function info($message, $context = [])
{
    app('log')->info($message, $context);
}

しかし debug() は、Debugbar のほうに繋がってた

# vendor/barryvdh/laravel-debugbar/src/helpers.php
function debug($value)
{
    $debugbar = debugbar();
    foreach (func_get_args() as $value) {
        $debugbar->addMessage($value, 'debug');
    }
}

答え

logger() をチェーンさせないで使えばいいらしい
これは分かんないよ~

# vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
function logger($message = null, array $context = [])
{
    if (is_null($message)) {
        return app('log');
    }

    return app('log')->debug($message, $context);
}
logger('デバッグてすと');
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?