introduce log verbosity, log parameters

master
Gilles Crettenand 11 years ago
parent fd563d3278
commit 0c99dd431e

@ -34,7 +34,7 @@ class Configuration {
),
'log' => array(
'file' => 'c:\\logs\\ws_ipad.txt',
'active' => false,
'verbosity' => 0, // The greater the verbosity, the more is displayed
),
'session' => array(
'save_path' => ''

@ -27,7 +27,16 @@ abstract class WebService
private $log = '';
public function log($message, $withTime = false) {
/**
* @param $message
* @param int $verbosity
* @param bool $withTime
*/
public function log($message, $verbosity = 1, $withTime = false) {
if(Configuration::get('log.verbosity') < $verbosity) {
return;
}
if($withTime) {
$message = date("d-m-Y h:m:s").' '.$message;
}
@ -38,7 +47,7 @@ abstract class WebService
public function Run()
{
$this->log("------------------");
$this->log("Start request", true);
$this->log("Start request", 1, true);
$data = array();
try {
@ -48,14 +57,15 @@ abstract class WebService
$data["error"]["code"] = $e->getCode();
$data["error"]["name"] = $e->getName();
$data["error"]["reason"] = $e->getMessage();
$this->log(sprintf("Failure : [%s] %s", $e->getCode(), $e->getName()));
}
$this->Send($data);
$this->log("Request finished", true);
$this->log("Request finished", 1, true);
$this->log("------------------\n\n");
if(Configuration::get('log.active')) {
if(Configuration::get('log.verbosity') > 0) {
file_put_contents(Configuration::get('log.file'), $this->log, FILE_APPEND | LOCK_EX);
}
}
@ -93,6 +103,7 @@ abstract class WebService
}
$this->log("Calling '".$this->func."'");
$this->log("Params: ".print_r($params, true), 2);
call_user_func_array(array($this, $this->func), $params);
}
@ -103,7 +114,7 @@ abstract class WebService
ob_clean();
flush();
$this->log("Data: ".print_r($data, true));
$this->log("Data: ".print_r($data, true), 2);
echo json_encode($data);
}
}

Loading…
Cancel
Save