Skip to content

Commit 7ee87a2

Browse files
committed
#34 - allow custom data in log objects
1 parent b30903d commit 7ee87a2

File tree

7 files changed

+47
-22
lines changed

7 files changed

+47
-22
lines changed

src/TgLog/Debug.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class Debug extends Message {
1111
/**
1212
* Constructs the debug.
1313
* @param string $message - the message text.
14+
* @param mixed $data - custom additional data for application specific usage.
1415
*/
15-
public function __construct($message) {
16-
parent::__construct('debug', $message);
16+
public function __construct($message, $data = NULL) {
17+
parent::__construct('debug', $message, $data);
1718
}
1819

19-
}
20+
}

src/TgLog/Error.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class Error extends Message {
1111
/**
1212
* Constructs the error.
1313
* @param string $message - the message text.
14+
* @param mixed $data - custom additional data for application specific usage.
1415
*/
15-
public function __construct($message) {
16-
parent::__construct('error', $message);
16+
public function __construct($message, $data = NULL) {
17+
parent::__construct('error', $message, $data);
1718
}
1819

19-
}
20+
}

src/TgLog/Info.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class Info extends Message {
1111
/**
1212
* Constructs the info.
1313
* @param string $message - the message text.
14+
* @param mixed $data - custom additional data for application specific usage.
1415
*/
15-
public function __construct($message) {
16-
parent::__construct('info', $message);
16+
public function __construct($message, $data = NULL) {
17+
parent::__construct('info', $message, $data);
1718
}
1819

19-
}
20+
}

src/TgLog/Log.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
*/
1313
class Log {
1414

15-
public const NONE = 'none';
16-
public const DEBUG = 'debug';
17-
public const INFO = 'info';
18-
public const WARN = 'warn';
19-
public const ERROR = 'error';
15+
public const NONE = 'none';
16+
public const DEBUG = 'debug';
17+
public const INFO = 'info';
18+
public const WARN = 'warn';
19+
public const ERROR = 'error';
20+
public const SUCCESS = 'success';
2021

2122
/** The available log priorities */
2223
protected static $logPriorities;

src/TgLog/Message.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ class Message {
1010

1111
protected $type;
1212
protected $message;
13+
protected $data;
1314

14-
public function __construct($type, $message) {
15+
public function __construct($type, $message, $data = NULL) {
1516
$this->type = $type;
1617
$this->message = $message;
18+
$this->data = $data;
1719
}
1820

1921
/**
@@ -31,4 +33,21 @@ public function getType() {
3133
public function getMessage() {
3234
return $this->message;
3335
}
34-
}
36+
37+
/**
38+
* Sets the custom additonal data
39+
* @param mixed $data - the data.
40+
*/
41+
public function setData($data) {
42+
$this->data = $data;
43+
return $this;
44+
}
45+
46+
/**
47+
* Returns the custom additonal data
48+
* @return mixed the data.
49+
*/
50+
public function getData() {
51+
return $this->data;
52+
}
53+
}

src/TgLog/Success.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class Success extends Message {
1111
/**
1212
* Constructs the success message.
1313
* @param string $message - the message text.
14+
* @param mixed $data - custom additional data for application specific usage.
1415
*/
15-
public function __construct($message) {
16-
parent::__construct('success', $message);
16+
public function __construct($message, $data = NULL) {
17+
parent::__construct('success', $message, $data);
1718
}
1819

19-
}
20+
}

src/TgLog/Warning.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class Warning extends Message {
1111
/**
1212
* Constructs the warning.
1313
* @param string $message - the message text.
14+
* @param mixed $data - custom additional data for application specific usage.
1415
*/
15-
public function __construct($message) {
16-
parent::__construct('warning', $message);
16+
public function __construct($message, $data = NULL) {
17+
parent::__construct('warning', $message, $data);
1718
}
1819

19-
}
20+
}

0 commit comments

Comments
 (0)