Skip to content

Commit

Permalink
Merge pull request #2 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
nguyenanhung authored Oct 7, 2018
2 parents 65273a6 + e1acc5d commit 21deb48
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/Helpers/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public function getLoggerSubPath()
*/
public function setLoggerPath($logger_path = '')
{
$this->loggerPath = trim($logger_path);
if (!empty($logger_path)) {
$this->loggerPath = trim($logger_path);
}
}

/**
Expand All @@ -121,7 +123,9 @@ public function setLoggerPath($logger_path = '')
*/
public function setLoggerSubPath($sub_path = '')
{
$this->loggerSubPath = trim($sub_path) . DIRECTORY_SEPARATOR;
if (!empty($sub_path)) {
$this->loggerSubPath = trim($sub_path) . DIRECTORY_SEPARATOR;
}
}

/**
Expand All @@ -147,7 +151,9 @@ public function getLoggerFilename()
*/
public function setLoggerFilename($logger_filename = '')
{
$this->loggerFilename = trim($logger_filename);
if (!empty($logger_filename)) {
$this->loggerFilename = trim($logger_filename);
}
}

/**
Expand All @@ -164,7 +170,7 @@ public function setLoggerFilename($logger_filename = '')
*
* @return bool|mixed|null
*/
public function log($level = '', $name = 'log', $msg = '', $context = [])
public function log($level = '', $name = 'log', $msg = 'My Message', $context = [])
{
$level = strtolower(trim($level));
if ($this->DEBUG == TRUE) {
Expand Down Expand Up @@ -220,11 +226,13 @@ public function log($level = '', $name = 'log', $msg = '', $context = [])
$stream->setFormatter($formatter);
$logger = new \Monolog\Logger(trim($name));
$logger->pushHandler($stream);

if (empty($msg)) {
$msg = 'My Log Message is Empty';
}
if (is_array($context)) {
return $logger->$useLevel(trim($msg), $context);
return $logger->$useLevel($msg, $context);
} else {
return $logger->$useLevel(trim($msg) . json_encode($context));
return $logger->$useLevel($msg . json_encode($context));
}
}
catch (\Exception $e) {
Expand All @@ -248,7 +256,7 @@ public function log($level = '', $name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function debug($name = 'log', $msg = '', $context = [])
public function debug($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('debug', $name, $msg, $context);
}
Expand All @@ -267,7 +275,7 @@ public function debug($name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function info($name = 'log', $msg = '', $context = [])
public function info($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('info', $name, $msg, $context);
}
Expand All @@ -285,7 +293,7 @@ public function info($name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function notice($name = 'log', $msg = '', $context = [])
public function notice($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('notice', $name, $msg, $context);
}
Expand All @@ -304,7 +312,7 @@ public function notice($name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function warning($name = 'log', $msg = '', $context = [])
public function warning($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('warning', $name, $msg, $context);
}
Expand All @@ -322,7 +330,7 @@ public function warning($name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function error($name = 'log', $msg = '', $context = [])
public function error($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('error', $name, $msg, $context);
}
Expand All @@ -341,7 +349,7 @@ public function error($name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function critical($name = 'log', $msg = '', $context = [])
public function critical($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('critical', $name, $msg, $context);
}
Expand All @@ -360,7 +368,7 @@ public function critical($name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function alert($name = 'log', $msg = '', $context = [])
public function alert($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('alert', $name, $msg, $context);
}
Expand All @@ -378,7 +386,7 @@ public function alert($name = 'log', $msg = '', $context = [])
*
* @return bool|mixed|null
*/
public function emergency($name = 'log', $msg = '', $context = [])
public function emergency($name = 'log', $msg = 'My Message', $context = [])
{
return $this->log('emergency', $name, $msg, $context);
}
Expand Down

0 comments on commit 21deb48

Please sign in to comment.