Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - Lumen Daily Logs

I want to add to my Lumen project a daily Log.

I try this in the app.php (Folder Bootstrap/)

$logFile = 'laravel.log';

Log::useDailyFiles(storage_path().'/logs/'.$logFile);

But this set me that error

Call to undefined method Monologlogger::useDailyFiles()

Any help I appreciate...Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you look at the framework source code here you can see that it will not do daily logs, but rather write to a single log file lumen.log. There is a public method available configureMonologUsing seen here and referenced here that you can use to override the default behavior without extending the Application.

Lumen just sets a handler to monolog, so another good solution is you could do this:

<?php

namespace AppProviders;

use IlluminateSupportServiceProvider;
use MonologFormatterLineFormatter;
use MonologHandlerRotatingFileHandler;

class LogServiceProvider extends ServiceProvider
{
    /**
     * Configure logging on boot.
     *
     * @return void
     */
    public function boot()
    {
        $maxFiles = 5;

        $handlers[] = (new RotatingFileHandler(storage_path("logs/lumen.log"), $maxFiles))
            ->setFormatter(new LineFormatter(null, null, true, true));

        $this->app['log']->setHandlers($handlers);
    }

    /**
     * Register the log service.
     *
     * @return void
     */
    public function register()
    {
        // Log binding already registered in vendor/laravel/lumen-framework/src/Application.php.
    }
}

Then don't forget to add the service provider to your Lumen bootstrap/app.php:

$app->register(AppProvidersLogServiceProvider::class);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...