Append a line to a logfile in the logs directory.
Date will be added automatically to the line.

@param string $name Name of the log file
@param mixed  $line Line to append

@return bool True on success, False on failure
510399
public static function write_log($name, $line)
    {
        if (!is_string($line)) {
            $line = var_export($line, true);
        }

        $date_format = $log_driver = $session_key = null;
        if (self::$instance) {
            $date_format = self::$instance->config->get('log_date_format');
            $log_driver  = self::$instance->config->get('log_driver');
            $session_key = intval(self::$instance->config->get('log_session_id', 8));
        }

        $date = rcube_utils::date_format($date_format);

        // trigger logging hook
        if (is_object(self::$instance) && is_object(self::$instance->plugins)) {
            $log = self::$instance->plugins->exec_hook('write_log',
                array('name' => $name, 'date' => $date, 'line' => $line));

            $name = $log['name'];
            $line = $log['line'];
            $date = $log['date'];

            if ($log['abort']) {
                return true;
            }
        }

        // add session ID to the log
        if ($session_key > 0 && ($sess = session_id())) {
            $line = '<' . substr($sess, 0, $session_key) . '> ' . $line;
        }

        if ($log_driver == 'syslog') {
            $prio = $name == 'errors' ? LOG_ERR : LOG_INFO;
            return syslog($prio, $line);
        }

        // write message with file name when configured to log to STDOUT
        if ($log_driver == 'stdout') {
            $stdout = "php://stdout";
            $line = "$name: $line";
            return file_put_contents($stdout, $line, FILE_APPEND) !== false;
        }

        // log_driver == 'file' is assumed here

        $line = sprintf("[%s]: %s\n", $date, $line);

        // per-user logging is activated
        if (self::$instance && self::$instance->config->get('per_user_logging') && self::$instance->get_user_id()) {
            $log_dir = self::$instance->get_user_log_dir();
            if (empty($log_dir) && !in_array($name, array('errors', 'userlogins', 'sendmail'))) {
                return false;
            }
        }

        if (empty($log_dir)) {
            if (!empty($log['dir'])) {
                $log_dir = $log['dir'];
            }
            else if (self::$instance) {
                $log_dir = self::$instance->config->get('log_dir');
            }
        }

        if (empty($log_dir)) {
            $log_dir = RCUBE_INSTALL_PATH . 'logs';
        }

        return file_put_contents("$log_dir/$name", $line, FILE_APPEND) !== false;
    }
28035
public function writeFreeFormLine($line)
	{
        if ($this->_logStatus == self::STATUS_LOG_OPEN
            && $this->_severityThreshold != self::OFF) {
            if (fwrite($this->_fileHandle, $line) === false) {
                $this->_messageQueue[] = $this->_messages['writefail'];
            }
        }
    }
972284
protected function appendToFile($logfile, $logstring, $explicit = false) {

		$class = \hlin\PHP::unn(__CLASS__);

		# logging signatures are intended to prevent duplication PER REQUEST
		# on a per logger instance basis, not cull duplicate messages per log

		$sig = crc32($logstring);
		$filesig = crc32($sig.$logfile);

		// have we already logged the message?
		if ( ! in_array($filesig, $this->filesigs)) {

			$fs = $this->fs;
			$filepath = $this->logspath.'/'.$logfile.'.log';
			$dir = $fs->dirname($filepath);

			if ( ! $fs->file_exists($dir)) {
				if ( ! $fs->mkdir($dir, $this->dirPermission(), true)) {
					$this->failedLogging(null, "[$class] Failed to create directories: $dir");
					return;
				}
			}

			// does the file exist?
			if ( ! $fs->file_exists($filepath)) {
				// ensure the file exists
				if ( ! $fs->touch($filepath)) {
					$this->failedLogging(null, "[$class] Failed to create log file: $filepath");
					return;
				}
				// ensure the permissions are right
				if ( ! $fs->chmod($filepath, $this->filePermission())) {
					$this->failedLogging(null, "[$class] Failed to set permissions on log file: $filepath");
					return;
				}
			}

			if ( ! $fs->file_append_contents($filepath, "$logstring\n")) {
				$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
			}

			// intentionally recording signature only after success
			$this->filesigs[] = $filesig;

			// have we stored the summary report?
			if ( ! $explicit && ! in_array($sig, $this->sigs)) {

				$filepath = $this->logspath.'/summary.log';

				# we don't need to ensure directory structure; it's already
				# been ensured by previous operations of recording the long
				# term complete log message

				// we only record the first line in the summary log
				if (($ptr = stripos($logstring, "\n")) !== false) {
					$summary = trim(substr($logstring, 0, $ptr));
				}
				else { // no end of line detected
					$summary = trim($logstring);
				}

				if ( ! $fs->file_append_contents($filepath, "$summary\n")) {
					$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
				}

				// intentionally recording signature only after success
				$this->sigs[] = $sig;
			}
		}
	}
24358
protected function writeLines($lines, $newline = false) {
		$docblock = '';
		if ($newline) {
			$docblock .= " *\n";
		}

		foreach ($lines as $line) {
			if (strpos($line, "\n")) {
				$sublines = explode("\n", $line);
				$line = array_shift($sublines);
				$docblock .= ' * ' . $line . "\n";
				$docblock .= $this->writeLines($sublines);
			} else {
				$docblock .= ' * ' . $line . "\n";
			}
		}
		
		return $docblock;
	}
342079
public function addOutput($line)
    {
        $this->lastOutputTime = microtime(true);

        fseek($this->stdout, 0, SEEK_END);
        fwrite($this->stdout, $line);
        fseek($this->stdout, $this->incrementalOutputOffset);
    }
381462
public function pushListLine($line, $flush = false)
    {
        if (trim($line)) {
            $infos = $this->parseListLine($line);

            if ($infos) {
                if ($this->lineInfo) {
                    $this->lineInfo['text'] = $this->createSpan($this->lineInfo['text']);
                    $this->buffer->addLine($this->lineInfo);
                }
                $this->lineInfo = $infos;
            } else {
                if ($this->listFlow || $line[0] == ' ') {
                    $this->lineInfo['text'][] = $line;
                } else {
                    $flush = true;
                }
            }
            $this->listFlow = true;
        } else {
            $this->listFlow = false;
        }

        if ($flush) {
            if ($this->lineInfo) {
                $this->lineInfo['text'] = $this->createSpan($this->lineInfo['text']);
                $this->buffer->addLine($this->lineInfo);
                $this->lineInfo = null;
            }

            return false;
        }

        return true;
    }
82954
protected function _log($textLine, $logPath=null)
    {
        // Return back to console also
        $this->_print($textLine);
        
        $logPath = ($logPath) ? $logPath : $this->logPath;

        if ($logPath)
            return file_put_contents($logPath, $this->_formatTextLine($textLine), FILE_APPEND);
        else
            return false;
    }
491551
static function create($name)
    {
        $logger = new Logger($name);
        $filename = SettingsPath::LOGS . mb_strtolower($name, 'UTF-8') . '.log';
        $handler = new RotatingFileHandler($filename);

        $handler->setFilenameFormat('{date}-{filename}', 'Y/m/d');

        $logger->pushHandler($handler);

        return $logger;
    }
575849
private function isHeaderIndexLine(string $line): bool
    {
        $matches = [];
        if (preg_match('#^index\s([a-z0-9]+)\.\.([a-z0-9]+)(.*)$#i', $line, $matches)) {
            $this->currentFile = new File($this->currentFileName, $this->currentOperation);
            return true;
        }
        return false;
    }
346331
public function end($name, $append = true)
    {
        $content = trim(ob_get_contents());
        ob_end_clean();

        $hash = md5($content);

        if (isset($this->hashCache[$hash])) {
            return;
        }

        $this->hashCache[$hash] = true;

        if (isset($this->blocks[$name]) && $append) {
            $this->blocks[$name] .= $content;
        } else {
            $this->blocks[$name] = $content;
        }
    }
1357578
public function ext($name, $path)
    {
        if(null === $path)
        {
            $path = File::path(dirname(Imi::getNamespacePath(App::getNamespace())), 'ide-helper');
        }
        foreach($name as $extName)
        {
            echo 'Generating ', $extName, '...', PHP_EOL;
            $extensionReflection = new ExtensionReflection($extName);
            $extensionReflection->save(File::path($path, $extName));
        }
        echo 'Complete!', PHP_EOL;
    }
438659
public function addInline($path, $name = null, $mime = true, $encoding = true)
    {
        $cid = static::generateId($this->client());
        $filename = basename($path);
        $this->_inlines[$path] = [
            'filename'    => $name ?: $filename,
            'disposition' => 'attachment',
            'mime'        => $mime,
            'headers'     => ['Content-ID: ' . $cid]
        ];
        return $cid;
    }
746467
public static function writeLines($path, $lines)
    {
        if (is_file($path) && !is_writable($path)) {
            throw new RuntimeException("File '$path' is not a writable file");
        }

        // make sure every line has only one newline at the end
        $lines = array_map(function ($line) {
            return rtrim($line);
        }, $lines);

        $bytes = file_put_contents($path, implode("\n", $lines));
        if ($bytes === false) {
            throw new RuntimeException("Something went wrong while writing content to '$path'");
        }

        return true;
    }
706352
public function addFile($name, $value)
    {
        $this->_hasFile = true;

        $filename = false;
        $contentType = 'application/octet-stream';
        if (is_resource($value)) {
            $content = stream_get_contents($value);
            if (stream_is_local($value)) {
                $finfo = new finfo(FILEINFO_MIME);
                $metadata = stream_get_meta_data($value);
                $contentType = $finfo->file($metadata['uri']);
                $filename = basename($metadata['uri']);
            }
        } else {
            $finfo = new finfo(FILEINFO_MIME);
            $value = substr($value, 1);
            $filename = basename($value);
            $content = file_get_contents($value);
            $contentType = $finfo->file($value);
        }
        $part = $this->newPart($name, $content);
        $part->type($contentType);
        if ($filename) {
            $part->filename($filename);
        }
        $this->add($part);

        return $part;
    }
705700
private function doSkip(string $line): bool
    {
        switch (true) {
            case (empty(trim($line))):
                // empty line
                $skip = true;
                break;
            case (1 == preg_match('/(#[\s\w]+)/', $line)):
                if (1 === $this->linecountOverall) {
                    $this->addName($line);
                }
                $skip = true;
                break;
            default:
                $skip = false;
        }

        return $skip;
    }
918700
private function get_plan_by_name( $name ) {
            $this->_logger->entrance();

            if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
                $this->_sync_plans();
            }

            foreach ( $this->_plans as $plan ) {
                if ( $name == $plan->name ) {
                    return $plan;
                }
            }

            return false;
        }
46326
def add_line(self, line, source, *lineno):
        """"""
        self.result.append(line, source, *lineno)