Make stdout logger use color
This commit is contained in:
parent
6ae814eebc
commit
213e548593
|
@ -32,3 +32,6 @@ openssl req -x509 -newkey rsa:4096 -nodes\
|
|||
# -keyout "$HOSTNAME.key.pem"\
|
||||
# -out "$HOSTNAME.cert.pem"
|
||||
# -addext "subjectAltName=DNS:example.com,DNS:www.example.net,IP:10.0.0.1"
|
||||
|
||||
# To inspect a cert use the following command
|
||||
#openssl x509 -in <path/to/cert/file> -text -noout
|
||||
|
|
|
@ -20,6 +20,19 @@ class Console extends \Qi_Console_Client
|
|||
return 0;
|
||||
}
|
||||
|
||||
$config = $this->makeConfig();
|
||||
|
||||
if (!$config->quiet) {
|
||||
print "Orbit // Gemini server software\n";
|
||||
print ":: Using cert file " . $config->tls_certfile . "\n";
|
||||
print ":: Using key file " . $config->tls_keyfile . "\n";
|
||||
}
|
||||
$server = new Server($config, $this->makeLogger($config));
|
||||
$server->listen();
|
||||
}
|
||||
|
||||
public function makeConfig()
|
||||
{
|
||||
$config = new Config();
|
||||
|
||||
if ($this->_args->host) {
|
||||
|
@ -58,21 +71,11 @@ class Console extends \Qi_Console_Client
|
|||
$config->tls_keyfile = sprintf("%s.key.pem", $config->hostname);
|
||||
}
|
||||
|
||||
if (!$config->quiet) {
|
||||
print "Orbit // Gemini server software\n";
|
||||
print ":: Using cert file " . $config->tls_certfile . "\n";
|
||||
print ":: Using key file " . $config->tls_keyfile . "\n";
|
||||
}
|
||||
$server = new Server($config, $this->makeLogger($config));
|
||||
$server->listen();
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function makeLogger($config)
|
||||
{
|
||||
$pid = getmypid();
|
||||
$output = "[%datetime%] $pid %channel%.%level_name%: %message% %context%\n";
|
||||
$formatter = new LineFormatter($output, 'Y-m-d\TH:i:s');
|
||||
|
||||
$logger = new Logger('orbit');
|
||||
|
||||
$level = Logger::INFO;
|
||||
|
@ -81,18 +84,34 @@ class Console extends \Qi_Console_Client
|
|||
}
|
||||
|
||||
$log_stream = new StreamHandler($config->log_file, $level);
|
||||
$log_stream->setFormatter($formatter);
|
||||
$log_stream->setFormatter($this->makeLogFormatter());
|
||||
$logger->pushHandler($log_stream);
|
||||
|
||||
if (!$config->quiet) {
|
||||
$std_stream = new StreamHandler('php://stdout', $level);
|
||||
$std_stream->setFormatter($formatter);
|
||||
$std_stream->setFormatter($this->makeLogFormatter(true));
|
||||
$logger->pushHandler($std_stream);
|
||||
}
|
||||
|
||||
return $logger;
|
||||
}
|
||||
|
||||
public function makeLogFormatter($is_tty = false)
|
||||
{
|
||||
$pid = getmypid();
|
||||
|
||||
if ($is_tty) {
|
||||
$output = "{2}[%datetime%]{} {3}$pid %channel%.%level_name%:{} %message% %context%\n";
|
||||
$output = str_replace("{2}", $this->_terminal->do_setaf(2), $output);
|
||||
$output = str_replace("{3}", $this->_terminal->do_setaf(3), $output);
|
||||
$output = str_replace("{}", $this->_terminal->do_op(), $output);
|
||||
} else {
|
||||
$output = "[%datetime%] $pid %channel%.%level_name%: %message% %context%\n";
|
||||
}
|
||||
|
||||
return new LineFormatter($output, 'Y-m-d\TH:i:s');
|
||||
}
|
||||
|
||||
public function showVersion()
|
||||
{
|
||||
print "Orbit " . Server::$version . "\n";
|
||||
|
|
Loading…
Reference in a new issue