Help us understand the problem. What is going on with this article?

Laravelのログを標準エラーに出力する

More than 3 years have passed since last update.

Laravelのログは通常storage/logsディレクトリに出力されます。

遊び程度にしか使っていませんが、私は開発時はartisan serveしたい派なので、ログは同じコンソールに出た方が嬉しい。なので標準エラーにログを出力するようにしてみます。

        $monolog = Log::getMonolog();
        $monolog->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr'));

こんなコードをどこかに書きます。どこが適切かはわかりませんが、一例としてはapp/Providors/ConfigServiceProvider.phpregister()メソッドの中などでもよいでしょう。
5.1のドキュメントには、bootstrap/app.phpの最後あたりで$app->configureMonologUsing()を呼べと書かれていました( http://laravel.com/docs/master/errors#configuration )。

app/bootstrap.php
$app->configureMonologUsing(function ($monolog) {
    $monolog->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr'));
});

return $app;

で、ログを出力します。

WelcomeController.php
    public function index(Request $request)
    {
            \Log::info("hello");
...

こんな感じに出力されます。

$ artisan serve
Laravel development server started on http://localhost:8000/
[2015-04-21 13:25:42] local.INFO: hello [] []
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした