public function log(string $level, string $message, array $context = []): void
    {
        if ($this->levelIsValid($level) === false) {
            throw new \InvalidArgumentException('Invalid log-level provided.');
        }

        // do not log if level is below min level:
        if ($this->isHandling($level) === false) {
            return;
        }

        $pathToLogfile = $this->openLogfile();
        $lineToLog = sprintf('[ %s ] %s: %s', date('Y-m-d H:i:s'), ucfirst($level), $message) . PHP_EOL;
        if (!empty($context)) {
            $lineToLog .= '--- Context ---' . PHP_EOL;
            $lineToLog .= print_r($context, true) . PHP_EOL;
        }
        file_put_contents($pathToLogfile, $lineToLog, FILE_APPEND);
    }
public function log(string $level, string $message, array $context = []): void
    {
        if ($this->levelIsValid($level) === false) {
            throw new \InvalidArgumentException('Invalid log-level provided.');
        }

        // do not log if level is below min level:
        if ($this->isHandling($level) === false) {
            return;
        }

        $pathToLogfile = $this->openLogfile();
        $lineToLog = sprintf('[ %s ] %s: %s', date('Y-m-d H:i:s'), ucfirst($level), $message) . PHP_EOL;
        if (!empty($context)) {
            $lineToLog .= '--- Context ---' . PHP_EOL;
            $lineToLog .= print_r($context, true) . PHP_EOL;
        }
        file_put_contents($pathToLogfile, $lineToLog, FILE_APPEND);
    }
public function log ( string $ level , string $ message , array $ context = [ ] ) : void { if ( $ this -> levelIsValid ( $ level ) === false ) { throw new \ InvalidArgumentException ( 'Invalid log-level provided.' ) ; } // do not log if level is below min level: if ( $ this -> isHandling ( $ level ) === false ) { return ; } $ pathToLogfile = $ this -> openLogfile ( ) ; $ lineToLog = sprintf ( '[ %s ] %s: %s' , date ( 'Y-m-d H:i:s' ) , ucfirst ( $ level ) , $ message ) . PHP_EOL ; if ( ! empty ( $ context ) ) { $ lineToLog .= '--- Context ---' . PHP_EOL ; $ lineToLog .= print_r ( $ context , true ) . PHP_EOL ; } file_put_contents ( $ pathToLogfile , $ lineToLog , FILE_APPEND ) ; }
Logs given event to a file.

@param string $level
@param string $message
@param array $context
Logs given event to a file .