@internal

@param array $log

@return array
341618
protected function formatLog(array $log): array
    {
        foreach ($log as &$logItem) {
            if ($logItem['type'] === 'model' || $logItem['type'] === 'field') {
                $logItem['action'] = $logItem['item']['action'];
            }

            if ($logItem['type'] === 'field') {
                $logItem['field'] = $logItem['item']['field'];
            }

            $formattedItem = $this->formatItem($logItem['type'], $logItem['item']);
            unset($logItem['item']);
            $logItem += $formattedItem;

            if (!empty($logItem['message'])) {
                continue;
            }

            if (is_array($logItem['permissions']) && array_key_exists('no_bypass', $logItem['permissions'])) {
                $logItem['permissions']['NO_BYPASS'] = $logItem['permissions']['no_bypass'];
                unset($logItem['permissions']['no_bypass']);
            }

            $typeKeys = array_keys($this->lpProxy->getTypes());

            $logItem['permission_no_bypass_checks'] = array_reverse($this->getPermissionNoBypassChecks($logItem['permissions'], $logItem['context'], $typeKeys));
            if (count($logItem['permission_no_bypass_checks']) == 1 && !empty($logItem['permission_no_bypass_checks'][0]['error'])) {
                $logItem['message'] = $logItem['permission_no_bypass_checks'][0]['error'];
            }

            $logItem['bypassed_access'] = $this->getBypassedAccess($logItem['permissions'], $logItem['context']);

            $purePermissions = $logItem['permissions'];
            unset($purePermissions['NO_BYPASS']);

            $logItem['permission_checks'] = array_reverse($this->getPermissionChecks($purePermissions, $logItem['context'], $typeKeys));
            if (count($logItem['permission_checks']) == 1 && !empty($logItem['permission_checks'][0]['error'])) {
                $logItem['message'] = $logItem['permission_checks'][0]['error'];
            }

            unset($logItem['context']);
        }
        unset($logItem);

        return $log;
    }
1334827
protected function getLogPath($log)
    {

        $dir = $this->log_root.'/'.$log.'/';

        if(!is_dir($dir)){
            mkdir($dir, 0777, true);
        }

        return $dir;
    }
191310
public function getLogs()
    {
        $realpath = (string) $this->getLogsRealpath();
        if (!$realpath) {
            return [];
        }

        $logs = trim($this->files->read($realpath));
        $logs = explode(PHP_EOL, $logs);

        return $logs;
    }
499133
function setLog($log) {
		if (!$log) {
			$this->logFile = null;
			$this->logCallback = null;
		} elseif (is_callable($log)) {
			$this->logFile = null;
			$this->logCallback = $log;
		} else {
			Files::create($log);
			$this->logFile = $log;
			$this->logCallback = null;
		}
		return $this;
	}
444965
public static function prepareForLogging($data)
    {
        if (empty($data)) {
            return [];
        }

        // If not an array, wrap it as an array
        if (!is_array($data)) {
            return [$data];
        }

        if (self::config()->logStyle == self::LOGSTYLE_SIMPLE) {
            return array_filter([
                isset($data['Message']) ? $data['Message'] : null,
                isset($data['Code']) ? $data['Code'] : null
            ]);
        }

        if (Director::isLive() || self::config()->logStyle == self::LOGSTYLE_VERBOSE) {
            self::sanitize($data);
        }

        return $data;
    }
1094742
public function getLog()
    {
        $log = [];
        foreach ($this->traces as $request => $traces) {
            $log[] = sprintf('%s: %s', $request, implode(', ', $traces));
        }

        return implode('; ', $log);
    }
196991
public function getLogs($level = null)
	{
		// If no level was given, return all logs.
		if(is_null($level))
		{
			return $this->logs;
		}

		else
		{
			if(isset($this->logs[$level]))
			{
				return $this->logs[$level];
			}
		}

		// If the level doesn't exist, just return an empty array.
		//
		// @todo: check that the level exists, otherwise throw an exception. 
		return array();
	}
925311
function collect() {
		foreach ( $this->_logs as &$log ) {
			if (!is_string($log['message'])) {
				$formated = $this->formatVars($log['message']);
				if ( $formated['exception'] ) {
					$log['label'] = '[ERROR]';
				}
				$log['message'] = $formated[0];
			}
		}
		return array(
			'messages'=>$this->_logs,
			'count'=>count($this->_logs),
		);
	}
342867
public function readLog(): array
    {
        $logFilePath = $this->getLogFilePath();

        if (!file_exists($logFilePath)) {
            return [];
        }

        $data = @unserialize(file_get_contents($logFilePath));

        if (false === $data) {
            throw new \RuntimeException('Could not unserialize log file '.$logFilePath);
        }

        return (array) $data;
    }
209030
public function toArray()
	{
		$list = parent::toArray();

		$list['log.facility'] = $this->getFacility();
		$list['log.timestamp'] = $this->getTimestamp();
		$list['log.priority'] = $this->getPriority();
		$list['log.message'] = $this->getMessage();
		$list['log.request'] = $this->getRequest();

		return $list;
	}
209905
public function FormatContent($Log) {
      $Data = $Log['Data'];

      // TODO: Check for a custom log type handler.

      switch ($Log['RecordType']) {
         case 'Activity':
            $Result = $this->FormatKey('Story', $Data);
            break;
         case 'Discussion':
            $Result =
               '<b>'.$this->FormatKey('Name', $Data).'</b><br />'.
               $this->FormatKey('Body', $Data);
            break;
         case 'ActivityComment':
         case 'Comment':
            $Result = $this->FormatKey('Body', $Data);
            break;
         case 'Configuration':
            $Result = $this->FormatConfiguration($Data);
            break;
         case 'Registration':
         case 'User':
            $Result = $this->FormatRecord(array('Email', 'Name'), $Data);
            if ($DiscoveryText = GetValue('DiscoveryText', $Data)) {
               $Result .= '<br /><b>'.T('Why do you want to join?').'</b><br />'.Gdn_Format::Display($DiscoveryText);
            }
            if (GetValue('Banned', $Data)) {
               $Result .= "<br />".T('Banned');
            }
            break;
         default:
            $Result = '';
      }
      return $Result;
   }
1368612
public function addLogs( $logs ) {
		if( !is_array( $logs ) && !$logs instanceof LogList ) {
			throw new InvalidArgumentException( '$logs needs to either be an array or a LogList object' );
		}
		if( $logs instanceof LogList ) {
			$logs = $logs->toArray();
		}
		foreach( $logs as $log ) {
			$this->addLog( $log );
		}
	}
1164913
protected function processLogs($logs)
	{
		static $syslogLevels=array(
			CLogger::LEVEL_TRACE=>LOG_DEBUG,
			CLogger::LEVEL_WARNING=>LOG_WARNING,
			CLogger::LEVEL_ERROR=>LOG_ERR,
			CLogger::LEVEL_INFO=>LOG_INFO,
			CLogger::LEVEL_PROFILE=>LOG_DEBUG,
		);

		openlog($this->identity,LOG_ODELAY|LOG_PID,$this->facility);
		foreach($logs as $log)
			syslog($syslogLevels[$log[1]],$this->formatLogMessage(str_replace("\n",', ',$log[0]),$log[1],$log[2],$log[3]));
		closelog();
	}
11922
public function getLogs(GetLogsRequest $request)
    {
        $headers = array();
        $params  = array();
        if ($request->getTopic() !== null) {
            $params ['topic'] = $request->getTopic();
        }
        if ($request->getFrom() !== null) {
            $params ['from'] = $request->getFrom();
        }
        if ($request->getTo() !== null) {
            $params ['to'] = $request->getTo();
        }
        if ($request->getQuery() !== null) {
            $params ['query'] = $request->getQuery();
        }
        $params ['type'] = 'log';
        if ($request->getLine() !== null) {
            $params ['line'] = $request->getLine();
        }
        if ($request->getOffset() !== null) {
            $params ['offset'] = $request->getOffset();
        }
        if ($request->getOffset() !== null) {
            $params ['reverse'] = $request->getReverse() ? 'true' : 'false';
        }

        $project  = $request->getProject() ?: '';
        $logStore = $request->getLogStore() ?: '';

        $resource = "/logstores/$logStore";
        list ( $resp, $header ) = $this->send("GET", $project, null, $resource, $params, $headers);

        $requestId = isset ( $header ['x-log-requestid'] ) ? $header ['x-log-requestid'] : '';
        $resp      = $this->parseToJson($resp, $requestId);

        return new GetLogsResponse ($resp, $header);
    }
1237673
public function getLogs()
	{
		if (file_exists($this->logPath))
		{
			$log = Filesystem::read($this->logPath);
			$levels = array();
			$this->logs = explode("\n", $log);
		}
		else
		{
			return array();
		}

		return $this->logs;
	}
1010299
public function save(array $log = [])
    {
        if ($this->config['single']) {
            $name        = is_string($single) ? $single : 'single';
            $destination = $this->config['path'] . $name . '.log';
        } else {
            $cli         = PHP_SAPI == 'cli' ? '_cli' : '';
            $destination = $this->config['path'] . date('Ym') . '/' . date('d') . $cli . '.log';
        }

        $path = dirname($destination);
        !is_dir($path) && mkdir($path, 0755, true);

        $info = '';
        foreach ($log as $type => $val) {
            $level = '';
            foreach ($val as $msg) {
                if (!is_string($msg)) {
                    $msg = var_export($msg, true);
                }
                $level .= '[ ' . $type . ' ] ' . $msg . "\r\n";
            }

            if (in_array($type, $this->config['apart_level'])) {
                // 独立记录的日志级别
                if ($this->config['single']) {
                    $filename = $path . '/' . $name . '_' . $type . '.log';
                } else {
                    $filename = $path . '/' . date('d') . '_' . $type . $cli . '.log';
                }

                $this->write($level, $filename, true);
            } else {
                $info .= $level;
            }
        }

        if ($info) {
            return $this->write($info, $destination);
        }

        return true;
    }
33544
public function log()
    {
        $result = [];
        if ($this->hasRequestParameter('messages')) {
            $messages = json_decode($this->getRawParameter('messages'), true);
            foreach ($messages as $message) {
                \common_Logger::singleton()->log($this->getLevel($message['level']), json_encode($message), ['frontend']);
            }
        }
        $this->returnJson($result);
    }