<?php

namespace Dipper\Foundation\Debugger\Requests;

use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;

/**
 * Class RequestsLogger
 */
class RequestsLogger
{
    protected $debuggingEnabled;

    protected $logger;

    protected $logFile;

    /**
     * RequestsLogger constructor.
     */
    public function __construct()
    {
        $this->prepareConfigs();
        $this->prepareLogger();
    }

    /**
     * @param \Dipper\Foundation\Debugger\Objects\Output $output
     */
    public function releaseOutput(Output $output)
    {
        if ($this->debuggingEnabled === true) {
            $this->logger->info($output->get());
        }
    }

    /**
     * @void
     */
    private function prepareConfigs()
    {
        $this->debuggingEnabled = config('dipper.debugger.requests.debug');
        $this->logFile = config('dipper.debugger.requests.log_file');
    }

    /**
     * @void
     */
    private function prepareLogger()
    {
        $handler = new StreamHandler(storage_path('logs/' . $this->logFile));
        $handler->setFormatter(new LineFormatter(null, null, true, true));

        $this->logger = new Logger('REQUESTS DEBUGGER');
        $this->logger->pushHandler($handler, Logger::INFO);
    }
}
