Skip to content

Commit 1a99b56

Browse files
committed
#13 - Logger interface
1 parent e760337 commit 1a99b56

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

src/TgLog/LogWrapper.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace TgLog;
4+
5+
/**
6+
* A wrapper that fulfills the logger interface.
7+
* @author ralph
8+
*
9+
*/
10+
class LogWrapper implements Logger {
11+
12+
/** The single instance of the log wrapper using the Log singleton */
13+
protected static $instance;
14+
15+
/**
16+
* Returns the single instance.
17+
* @return LogWrapper - single Log instance
18+
*/
19+
public static function instance() {
20+
if (self::$instance == null) {
21+
self::$instance = new LogWrapper(Log::instance());
22+
}
23+
return self::$instance;
24+
}
25+
26+
/** The underlying log */
27+
protected $log;
28+
29+
/**
30+
* Constructor.
31+
* @param Log $log - the underlying logger
32+
*/
33+
public function __construct(Log $log) {
34+
if ($log == NULL) $log = Log::instance();
35+
$this->log = $log;
36+
}
37+
38+
/**
39+
* @see \TgLog\Logger::warn()
40+
*/
41+
public function warn($s, $object = NULL) {
42+
$this->log->logWarn($s, $object);
43+
}
44+
45+
/**
46+
* @see \TgLog\Logger::debug()
47+
*/
48+
public function debug($s, $object = NULL) {
49+
$this->log->logDebug($s, $object);
50+
}
51+
52+
/**
53+
* @see \TgLog\Logger::error()
54+
*/
55+
public function error($s, $object = NULL) {
56+
$this->log->logError($s, $object);
57+
}
58+
59+
/**
60+
* @see \TgLog\Logger::info()
61+
*/
62+
public function info($s, $object = NULL) {
63+
$this->log->logInfo($s, $object);
64+
}
65+
}
66+

src/TgLog/Logger.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace TgLog;
4+
5+
/**
6+
* Interface to make it easier to integrate other log implementations.
7+
*/
8+
interface Logger {
9+
10+
/**
11+
* Log the given string (and $object) in DEBUG level.
12+
* @param string $s - the string to be logged
13+
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
14+
*/
15+
public function debug(string $s, $object = NULL);
16+
17+
/**
18+
* Log the given string (and $object) in DEBUG level.
19+
* @param string $s - the string to be logged
20+
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
21+
*/
22+
public function info(string $s, $object = NULL);
23+
24+
/**
25+
* Log the given string (and $object) in WARN level.
26+
* @param string $s - the string to be logged
27+
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
28+
*/
29+
public function warn(string $s, $object = NULL);
30+
31+
/**
32+
* Log the given string (and $object) in DEBUG level.
33+
* @param string $s - the string to be logged
34+
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
35+
*/
36+
public function error(string $s, $object = NULL);
37+
38+
}

0 commit comments

Comments
 (0)