Commit 7e40f599 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Logger: Move support::log() to logger::logMessage.

Support: removed Function log().
Database: Use of new class Logger.
parent 551dbd17
......@@ -22,6 +22,7 @@ require_once(__DIR__ . '/exceptions/DbException.php');
require_once(__DIR__ . '/store/Store.php');
require_once(__DIR__ . '/helper/Support.php');
require_once(__DIR__ . '/helper/Logger.php');
require_once(__DIR__ . '/helper/BindParam.php');
/**
......@@ -50,6 +51,10 @@ class Database {
*/
private $mysqli_result = null;
/**
* @var string
*/
private $sqlLog = '';
/**
* Returns current data base handle from Store[System][SYSTEM_DBH].
......@@ -64,6 +69,7 @@ class Database {
if ($this->mysqli === null) {
$this->mysqli = $this->dbConnect();
}
$this->sqlLog = $this->store->getVar(SYSTEM_SQL_LOG, STORE_SYSTEM);
}
......@@ -379,7 +385,7 @@ class Database {
$msg .= ']';
Support::log($msg);
Logger::logMessage($msg, $this->sqlLog);
}
/**
......
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 2/18/16
* Time: 5:30 PM
*/
namespace qfq;
require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../exceptions/UserException.php');
class Logger {
/**
* Haengt $msg an $filename an
*
* @param $msg
* @param $filename
* @throws UserException
*/
public static function logMessage($msg, $filename) {
if (!$handle = fopen($filename, 'a')) {
throw new UserException("Error - cannot open. File: " . $filename, ERROR_IO_OPEN);
}
if (fwrite($handle, $msg . PHP_EOL) === FALSE) {
throw new UserException("Error - cannot write. File: " . $filename, ERROR_IO_WRITE);
}
fclose($handle);
} // logMessage()
}
\ No newline at end of file
......@@ -48,25 +48,4 @@ class Support {
return implode('&', $items);
}
/**
* @throws CodeException
*/
public static function log($text) {
$logFile = __DIR__ . '/../../../' . QFQ_LOG;
if (!is_writable($logFile)) {
throw new CodeException ("The file (" . dirname($_SERVER['SCRIPT_FILENAME']) . '/) ' . $logFile . " is not writable ()", ERROR_LOG_NOT_WRITABLE);
}
if (!$handle = fopen($logFile, 'a')) {
throw new CodeException ("Cannot open file to append: " . $logFile, ERROR_LOG_NOT_WRITABLE);
}
if (fwrite($handle, $text . chr(10)) === FALSE) {
throw new CodeException ("Cannot write to file: " . $logFile, ERROR_LOG_NOT_WRITABLE);
}
fclose($handle);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment