Skip to content

Commit

Permalink
#34 - allow custom data in log objects
Browse files Browse the repository at this point in the history
  • Loading branch information
technicalguru committed Jul 14, 2021
1 parent b30903d commit 7ee87a2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/TgLog/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class Debug extends Message {
/**
* Constructs the debug.
* @param string $message - the message text.
* @param mixed $data - custom additional data for application specific usage.
*/
public function __construct($message) {
parent::__construct('debug', $message);
public function __construct($message, $data = NULL) {
parent::__construct('debug', $message, $data);
}

}
}
7 changes: 4 additions & 3 deletions src/TgLog/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class Error extends Message {
/**
* Constructs the error.
* @param string $message - the message text.
* @param mixed $data - custom additional data for application specific usage.
*/
public function __construct($message) {
parent::__construct('error', $message);
public function __construct($message, $data = NULL) {
parent::__construct('error', $message, $data);
}

}
}
7 changes: 4 additions & 3 deletions src/TgLog/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class Info extends Message {
/**
* Constructs the info.
* @param string $message - the message text.
* @param mixed $data - custom additional data for application specific usage.
*/
public function __construct($message) {
parent::__construct('info', $message);
public function __construct($message, $data = NULL) {
parent::__construct('info', $message, $data);
}

}
}
11 changes: 6 additions & 5 deletions src/TgLog/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
*/
class Log {

public const NONE = 'none';
public const DEBUG = 'debug';
public const INFO = 'info';
public const WARN = 'warn';
public const ERROR = 'error';
public const NONE = 'none';
public const DEBUG = 'debug';
public const INFO = 'info';
public const WARN = 'warn';
public const ERROR = 'error';
public const SUCCESS = 'success';

/** The available log priorities */
protected static $logPriorities;
Expand Down
23 changes: 21 additions & 2 deletions src/TgLog/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ class Message {

protected $type;
protected $message;
protected $data;

public function __construct($type, $message) {
public function __construct($type, $message, $data = NULL) {
$this->type = $type;
$this->message = $message;
$this->data = $data;
}

/**
Expand All @@ -31,4 +33,21 @@ public function getType() {
public function getMessage() {
return $this->message;
}
}

/**
* Sets the custom additonal data
* @param mixed $data - the data.
*/
public function setData($data) {
$this->data = $data;
return $this;
}

/**
* Returns the custom additonal data
* @return mixed the data.
*/
public function getData() {
return $this->data;
}
}
7 changes: 4 additions & 3 deletions src/TgLog/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class Success extends Message {
/**
* Constructs the success message.
* @param string $message - the message text.
* @param mixed $data - custom additional data for application specific usage.
*/
public function __construct($message) {
parent::__construct('success', $message);
public function __construct($message, $data = NULL) {
parent::__construct('success', $message, $data);
}

}
}
7 changes: 4 additions & 3 deletions src/TgLog/Warning.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class Warning extends Message {
/**
* Constructs the warning.
* @param string $message - the message text.
* @param mixed $data - custom additional data for application specific usage.
*/
public function __construct($message) {
parent::__construct('warning', $message);
public function __construct($message, $data = NULL) {
parent::__construct('warning', $message, $data);
}

}
}

0 comments on commit 7ee87a2

Please sign in to comment.