xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / log.inc.php (08fa1d58abf71b1a2bb5b7dc77eead4e74e8f49a) (1,609B) (mode 100644) [raw]
<?php
require_once($INC . "/util.inc.php");

if (!isset($rg_log_dir))
	$rg_log_dir = "/var/log/rocketgit";

if (!isset($rg_web_log_dir))
	$rg_web_log_dir = "/var/log/rocketgit-web";

$rg_log_file = $rg_log_dir . "/fallback.log";
$rg_log_fd = FALSE;
$rg_log_sid = rg_id(6);

function rg_log_set_file($file)
{
	global $rg_log_file;

	$rg_log_file = $file;
}

function rg_log($str)
{
	global $rg_log_file;
	global $rg_log_fd;
	global $rg_log_sid;

	if ($rg_log_fd === FALSE) {
		$rg_log_fd = @fopen($rg_log_file, "a");
		if ($rg_log_fd === FALSE)
			return;
		// write an empty line
		fwrite($rg_log_fd, "\n");
	}

	$t = gettimeofday();

	$buf0 = gmdate("Y-m-d H:i:s", $t['sec']) . "." . sprintf("%03u", $t['usec'] / 1000);
	$buf0 .= " " . $rg_log_sid . " ";
	$buf = "";
	$str = preg_replace_callback('/[^\pL\pN\pP\pS \t]/uU', "rg_callback_hexa", $str);
	$buf .= $buf0 . $str . "\n";

	if ($rg_log_fd !== NULL)
		fwrite($rg_log_fd, $buf);
}

/*
 * Log a multiline string
 */
function rg_log_ml($str)
{
	$lines = explode("\n", $str);
	if (empty($lines))
		return;

	foreach ($lines as $line)
		rg_log($line);
}

function rg_fatal($msg)
{
	rg_log("FATAL: $msg");

	$bt = debug_backtrace();
	rg_log_ml("Backtrace: " . print_r($bt, TRUE));
	exit(1);
}

function rg_internal_error($msg)
{
	rg_log("Internal error: $msg");

	$bt = debug_backtrace();
	rg_log_ml("Backtrace: " . print_r($bt, TRUE));
}

// TODO: send mail or store all data in database
function rg_security_violation($msg)
{
	rg_log("Security violation: $msg");

	$bt = debug_backtrace();
	rg_log_ml("Backtrace: " . print_r($bt, TRUE));

	exit(1);
}

?>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master