<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //check that app is local
        // if ($this->app->isLocal()) {
            //if local register your services you require for development
            // $this->app->register('Barryvdh\Debugbar\ServiceProvider');
        // } else {
        //else register your services you require for production
            // $this->app['request']->server->set('HTTPS', true);
        // }
        
        $this->app->singleton('job_log', function ($app) {
            $handler = new RotatingFileHandler(
                storage_path('logs/jobs/jobs.log'),
                0,
                Logger::DEBUG
            );
            
            // Create a new logger instance
            $logger = new Logger('job_log');
            
            // Create a line formatter
            $formatter = new LineFormatter(
                "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
                "Y-m-d H:i:s",
                true,
                true
            );
            
            // Set the formatter
            $handler->setFormatter($formatter);
            
            $logger->pushHandler($handler);

            return $logger;
        });
    }
}
