Skip to content

Commit 92e2844

Browse files
committed
Releasing 1.1.0
2 parents d4c5820 + 1a99b56 commit 92e2844

File tree

5 files changed

+249
-55
lines changed

5 files changed

+249
-55
lines changed

src/TgLog/Log.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ public function __construct($logLevel = self::INFO, $appName = NULL) {
102102
protected function log($sev, $s, $o = null) {
103103
if (!is_string($s)) $s = json_encode($s, JSON_PRETTY_PRINT);
104104
if ($o != null) {
105-
if ($o instanceof \Exception) {
106-
$s .= get_class($o).' "'.$o->getCode().' - '.$o->getMessage()."\" at\n".$o->getTraceAsString();
105+
if ($o instanceof \Throwable) {
106+
$s .= ': '.get_class($o).' "'.$o->getCode().' - '.$o->getMessage()."\" at\n".$o->getTraceAsString();
107107
} else {
108-
$s .= json_encode($o, JSON_PRETTY_PRINT);
108+
$s .= ': '.json_encode($o, JSON_PRETTY_PRINT);
109109
}
110110
}
111111
$this->messages[$sev][] = $s;

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+
}

src/TgUtils/Date.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ class Date extends \DateTime {
3737
const MONTH_ABBR = "\x023\x03";
3838
const MONTH_NAME = "\x024\x03";
3939

40+
/** Seconds per minute */
41+
public const SECONDS_PER_MINUTE = 60;
42+
/** Seconds per hour */
43+
public const SECONDS_PER_HOUR = 3600;
44+
/** Seconds per day */
45+
public const SECONDS_PER_DAY = 86400;
46+
/** Seconds per week */
47+
public const SECONDS_PER_WEEK = 604800;
48+
4049
/**
4150
* The format string to be applied when using the __toString() magic method.
4251
*

0 commit comments

Comments
 (0)