Write Log File

Generally this function will be called using the global log_message() function

@access	public
@param	int|string	the error level
@param	string	the error message
@param	string	information about the method
@return	bool
542588
public static function write($level, $msg, $method = null)
	{
		// defined default error labels
		static $oldlabels = array(
			1  => 'Error',
			2  => 'Warning',
			3  => 'Debug',
			4  => 'Info',
		);

		// get the levels defined to be logged
		$loglabels = \Config::get('log_threshold');

		// bail out if we don't need logging at all
		if ($loglabels == \Fuel::L_NONE)
		{
			return false;
		}

		// if it's not an array, assume it's an "up to" level
		if ( ! is_array($loglabels))
		{
			$a = array();
			foreach (static::$levels as $l => $label)
			{
				$l >= $loglabels and $a[] = $l;
			}
			$loglabels = $a;
		}

		// if profiling is active log the message to the profile
		if (\Config::get('profiling'))
		{
			\Console::log($method.' - '.$msg);
		}

		// convert the level to monolog standards if needed
		if (is_int($level) and isset($oldlabels[$level]))
		{
			$level = strtoupper($oldlabels[$level]);
		}
		if (is_string($level))
		{
			if ( ! $level = array_search($level, static::$levels))
			{
				$level = 250;	// can't map it, convert it to a NOTICE
			}
		}

		// make sure $level has the correct value
		if ((is_int($level) and ! isset(static::$levels[$level])) or (is_string($level) and ! array_search(strtoupper($level), static::$levels)))
		{
			throw new \FuelException('Invalid level "'.$level.'" passed to logger()');
		}

		// do we need to log the message with this level?
		if ( ! in_array($level, $loglabels))
		{
			return false;
		}

		// log the message
		static::instance()->log($level, (empty($method) ? '' : $method.' - ').$msg);

		return true;
	}
1014140
protected function write($line, $level = 100)
    {
        $logfile = $this->getFilePath($level);
        $rotator = $this->getRotator($logfile);
        $return = $rotator->write($line);

        if ($this->isErrorLevel($level) && true===$this->duplicate_errors)
            self::write($line, 100);

        return $return;
    }
706515
public function log($level, $message, array $context = [])
    {
        $context_output = empty($context) ? '' : sprintf(' :: %s', json_encode($context));

        $logline = sprintf("[%s] %s%s\n", strtoupper($level), $message, $context_output);

        $handle = in_array($level, self::ERROR_LEVELS, false) ? STDERR : STDOUT;

        fwrite($handle, $logline);
    }
790235
function _append_log($message_number, $message)
    {
        // remove the byte identifying the message type from all but the first two messages (ie. the identification strings)
        if (strlen($message_number) > 2) {
            $this->_string_shift($message);
        }

        switch (NET_SSH2_LOGGING) {
            // useful for benchmarks
            case self::LOG_SIMPLE:
                $this->message_number_log[] = $message_number;
                break;
            // the most useful log for SSH2
            case self::LOG_COMPLEX:
                $this->message_number_log[] = $message_number;
                $this->log_size+= strlen($message);
                $this->message_log[] = $message;
                while ($this->log_size > self::LOG_MAX_SIZE) {
                    $this->log_size-= strlen(array_shift($this->message_log));
                    array_shift($this->message_number_log);
                }
                break;
            // dump the output out realtime; packets may be interspersed with non packets,
            // passwords won't be filtered out and select other packets may not be correctly
            // identified
            case self::LOG_REALTIME:
                switch (PHP_SAPI) {
                    case 'cli':
                        $start = $stop = "\r\n";
                        break;
                    default:
                        $start = '<pre>';
                        $stop = '</pre>';
                }
                echo $start . $this->_format_log(array($message), array($message_number)) . $stop;
                @flush();
                @ob_flush();
                break;
            // basically the same thing as self::LOG_REALTIME with the caveat that self::LOG_REALTIME_FILE
            // needs to be defined and that the resultant log file will be capped out at self::LOG_MAX_SIZE.
            // the earliest part of the log file is denoted by the first <<< START >>> and is not going to necessarily
            // at the beginning of the file
            case self::LOG_REALTIME_FILE:
                if (!isset($this->realtime_log_file)) {
                    // PHP doesn't seem to like using constants in fopen()
                    $filename = self::LOG_REALTIME_FILENAME;
                    $fp = fopen($filename, 'w');
                    $this->realtime_log_file = $fp;
                }
                if (!is_resource($this->realtime_log_file)) {
                    break;
                }
                $entry = $this->_format_log(array($message), array($message_number));
                if ($this->realtime_log_wrap) {
                    $temp = "<<< START >>>\r\n";
                    $entry.= $temp;
                    fseek($this->realtime_log_file, ftell($this->realtime_log_file) - strlen($temp));
                }
                $this->realtime_log_size+= strlen($entry);
                if ($this->realtime_log_size > self::LOG_MAX_SIZE) {
                    fseek($this->realtime_log_file, 0);
                    $this->realtime_log_size = strlen($entry);
                    $this->realtime_log_wrap = true;
                }
                fputs($this->realtime_log_file, $entry);
        }
    }
1301552
private function _log_to_file($error_text)
    {
        try {
            $dir_name = 'logs';
            if (!is_dir($dir_name)) {
                mkdir($dir_name);
            }
            $fileName = $dir_name.'/'.__CLASS__.'-'.date('Y-m-d').'.txt';
            $myFile = fopen($fileName, 'a+');
            $date = '============[Date]============';
            $date .= "\n";
            $date .= '[ '.date('Y-m-d H:i:s  e').' ] ';
            fwrite($myFile, $date.$error_text."\n\n");
            fclose($myFile);
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }
1244816
public static function errorHandler($level, $message, $file, $line)
    {
        if (! ($level & error_reporting()))
            return false;
        switch ($level) {
            case E_NOTICE:
            case E_USER_NOTICE:
                $method = 'notice';
                $type = 'Notice';
                break;
            case E_WARNING:
            case E_USER_WARNING:
                $method = 'warn';
                $type = 'Warning';
                break;
            case E_ERROR:
            case E_USER_ERROR:
                $method = 'crit';
                $type = 'Fatal Error';
                break;
            default:
                $method = 'err';
                $type = 'Unknown, ' . $level;
                break;
        }
        self::$errors[] = array(
            'type' => $type ,
            'message' => $message ,
            'file' => $file ,
            'line' => $line,
            'trace' => debug_backtrace()
        );

        $message = sprintf(
            "%s in %s on line %d",
            $message,
            str_replace($_SERVER['DOCUMENT_ROOT'], '', $file),
            $line
        );
        // if (ini_get('log_errors'))
        //     error_log(sprintf("%s: %s", $type, $message));

        if (($logger = self::getLogger())) {
            $logger->$method($message);
        }
        return false;
    }
1272314
public function write($level, $message, array $context = array())
    {
        $filename = $this->filenameLevels[$level] ?: $this->defaultFile;
        $context = array('__context' => $context);
        $log = $this->format($level, $message, $context);
        $logDir = dirname($filename);

        // Error are suppressed because an Exception will be thrown instead
        if (!is_dir($logDir)) {
            if (@mkdir($logDir, 0777, true) === false) {
                throw new RuntimeException('Failed to create log directory. Please check permissions.');
            }
        }

        if (@file_put_contents($filename, $log, FILE_APPEND | LOCK_EX) === false) {
            throw new RuntimeException('Failed to write log file. Please check permissions.');
        }

        $this->setLastLogLine($log);

        return true;
    }
575407
public function writeError($line, $check, $message, $level = WARNING) {
		// echo $this->currentPhpFile . " " . $level . " Line:" . $line . " - " . $message . "\n";
		$this->outputFile[$this->currentPhpFile][$line][] = array(
			"level"   => $level,
			"line"    => $line,
			"message" => $message,
			"check"   => $check,
		);
	}
708673
public function addError($error, $file = __FILE__, $line = __LINE__, $type = ERROR_INFORMATION, $log = LOG_SYSTEM) {
        if ($log != LOG_HISTORY && $log != LOG_CRONS && $log != LOG_EVENT) {
            if (Config::config()['user']['debug']['log']) {
                if ($log == LOG_SQL) {
                    $error = preg_replace('#([\t]{2,})#isU', "", $error);
                }

                $data = date("d/m/Y H:i:s : ", time()) . '[' . $type . '] file ' . $file . ' / line ' . $line . ' / ' . $error;
                file_put_contents(APP_LOG_PATH . $log . '.log', $data . "\n", FILE_APPEND | LOCK_EX);

                if ((Config::config()['user']['debug']['error']['error'] && $type == ERROR_FATAL) || (Config::config()['user']['debug']['error']['exception'] == true && $type == ERROR_EXCEPTION) || preg_match('#Exception#isU', $type) || (Config::config()['user']['debug']['error']['fatal'] == true && $type == ERROR_ERROR)) {
                    if (CONSOLE_ENABLED == MODE_HTTP) {
                        echo $data . "\n<br />";
                    }
                    else {
                        echo $data . "\n";
                    }
                }
            }
        }
        else {
            file_put_contents(APP_LOG_PATH . $log . '.log', $error . "\n", FILE_APPEND | LOCK_EX);
        }
    }
711000
private function writeLog($message, array $context, $intLevel)
    {
        $file = $this->getLogLocation($intLevel);
        $verboseDebug = $this->verboseDebugging();

        /**
          The 'logfile' context value just exists for testing
          purposes. Calling code should not rely on this
          behavior 
        */
        if (isset($context['logfile'])) {
            $file = $context['logfile'];
        }
        if (isset($context['verbose'])) {
            $verboseDebug = true;
        }
        if ($file) {
            $fptr = fopen($file, 'a');
            fwrite($fptr, $this->rfcLogLine($message, $intLevel) . "\n");
            if ($this->syslogHost && !isset($context['skip_remote'])) {
                $this->syslogRemote($message);
            }
            if ($intLevel === self::DEBUG && $verboseDebug) {
                $stack = array();
                if (isset($context['exception']) && $context['exception'] instanceof \Exception) {
                    $stack = $this->stackTrace($context['exception']->getTrace());
                } else {
                    $stack = $this->stackTrace(debug_backtrace());
                }
                foreach ($stack as $frame) {
                    fwrite($fptr, $this->rfcLogLine($frame, $intLevel) . "\n");
                }
            }
            fclose($fptr);
        }
    }
663480
public void write(String logService, LogLevel level, String msg)
	{
		doWrite(logService, level, msg, null);
	}
23671
private function writeLogs(): void
    {
        // Write logs
        $fileName = $this->getApp()->getConfig()->getDirectory(ConfigInterface::DIR_VAR_LOGS) . '/Berlioz.log';

        if (is_resource($this->fp) || is_resource($this->fp = @fopen($fileName, 'a'))) {
            if (count($this->logs) > 0) {
                foreach ($this->logs as $key => $log) {
                    if (!$log['written']) {
                        $line = sprintf("%-26s %-11s %s\n",
                                        \DateTime::createFromFormat('U.u', number_format($log['time'], 6, '.', ''))
                                                 ->format('Y-m-d H:i:s.u'),
                                        '[' . $log['level'] . ']',
                                        $log['message']);

                        if (@fwrite($this->fp, $line) !== false) {
                            $this->logs[$key]['written'] = true;
                        }
                    }
                }
            }
            unset($log);
        }
    }
739718
public function write($content, $level)
    {
        $this->message = (string) $content;
        $this->level   = $level;

        if ( is_callable($this->writeBeforeHandle) )
        {
            $this->writeBefore($this->writeBeforeHandle);

            if (!$this->customMessageFormatParser)
            {
                $this->defaultMessageFormatReplaces();
            }
        }
        else
        {
            $this->defaultMessageFormatReplaces();
        }

        $this->messageFormatParser();

        if ( !$this->resource )
        {
            $this->filename = date($this->dateFormat);

            if ( !empty($this->extension) )
            {
                $this->filename .= '.' . $this->extension;
            }

            $this->resource = fopen($this->path . DIRECTORY_SEPARATOR . $this->filename, 'a');
        }

        fwrite($this->resource, $this->messageOutput . PHP_EOL);
    }
45540
public function write($str) {
        if (feof($this->outputHandle)) {
            trigger_error('Called LogFormatter::write() but file handle was closed.', E_USER_WARNING);
            return;
        }
        fwrite($this->outputHandle, $str);
    }
1345107
public void write(String logService, LogLevel level, String msg)
	{
		doFileWrite(logService, level, msg, null);
	}
580496
protected function writeToLog($entry) {
		if ($entry[0] >= $this->logLevel) {
			trigger_error("** ".$this->getFormattedCaller()." ** {$entry[1]} **",$this->loggerTypes[$entry[0]]->getPhpErrorCode());
		}
	}
326249
function write($level,$text,$context = []){
		if(isset($this->log[$level])){
		
			$log = $this->log[$level];

			$log->addRecord($level,$text,$context);
		}
	}