diff --git a/configuration.php b/configuration.php index 7a35e17..20f53ec 100644 --- a/configuration.php +++ b/configuration.php @@ -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' => '' diff --git a/mobile.webservice.php b/mobile.webservice.php index 4385bd5..5a1082a 100644 --- a/mobile.webservice.php +++ b/mobile.webservice.php @@ -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); } }