logging methods

This commit is contained in:
Steffen Schröder 2014-06-17 22:37:34 +02:00
parent 1e641f69c6
commit 296fb77028
2 changed files with 43 additions and 10 deletions

View File

@ -34,20 +34,14 @@ require_once ManiaControlDir . 'core' . DIRECTORY_SEPARATOR . 'AutoLoader.php';
\ManiaControl\Logger::setup();
/**
* Log and echo the given text
*
* @param string $message
* @param bool $eol
* @deprecated
* @see \ManiaControl\Logger::log()
*/
function logMessage($message, $eol = true) {
error_log($message);
if ($eol) {
$message = '[' . date('d-M-Y H:i:s e') . '] ' . $message . PHP_EOL;
}
echo $message;
\ManiaControl\Logger::log($message, $eol);
}
logMessage('Starting ManiaControl...');
\ManiaControl\Logger::log('Starting ManiaControl...');
// Check requirements
\ManiaControl\Utils\SystemUtil::checkRequirements();

View File

@ -29,4 +29,43 @@ class Logger {
$logFileName .= '.log';
ini_set('error_log', $logFileName);
}
/**
* Log and echo the given Error Message
*
* @param string $message
* @param bool $eol
* @param bool $output
*/
public static function logError($message, $eol = true, $output = true) {
$message = '[ERROR] ' . $message;
self::log($message, $eol, $output);
}
/**
* Log and output the given Message
*
* @param string $message
* @param bool $eol
* @param bool $output
*/
public static function log($message, $eol = true, $output = true) {
error_log($message);
if ($output) {
self::output($message, $eol);
}
}
/**
* Echo the given Message
*
* @param string $message
* @param bool $eol
*/
public static function output($message, $eol = true) {
if ($eol) {
$message = '[' . date('d-M-Y H:i:s e') . '] ' . $message . PHP_EOL;
}
echo $message;
}
}