Skip to content

Commit

Permalink
Releasing 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
technicalguru committed Dec 11, 2020
2 parents d4c5820 + 1a99b56 commit 92e2844
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 55 deletions.
6 changes: 3 additions & 3 deletions src/TgLog/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public function __construct($logLevel = self::INFO, $appName = NULL) {
protected function log($sev, $s, $o = null) {
if (!is_string($s)) $s = json_encode($s, JSON_PRETTY_PRINT);
if ($o != null) {
if ($o instanceof \Exception) {
$s .= get_class($o).' "'.$o->getCode().' - '.$o->getMessage()."\" at\n".$o->getTraceAsString();
if ($o instanceof \Throwable) {
$s .= ': '.get_class($o).' "'.$o->getCode().' - '.$o->getMessage()."\" at\n".$o->getTraceAsString();
} else {
$s .= json_encode($o, JSON_PRETTY_PRINT);
$s .= ': '.json_encode($o, JSON_PRETTY_PRINT);
}
}
$this->messages[$sev][] = $s;
Expand Down
66 changes: 66 additions & 0 deletions src/TgLog/LogWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace TgLog;

/**
* A wrapper that fulfills the logger interface.
* @author ralph
*
*/
class LogWrapper implements Logger {

/** The single instance of the log wrapper using the Log singleton */
protected static $instance;

/**
* Returns the single instance.
* @return LogWrapper - single Log instance
*/
public static function instance() {
if (self::$instance == null) {
self::$instance = new LogWrapper(Log::instance());
}
return self::$instance;
}

/** The underlying log */
protected $log;

/**
* Constructor.
* @param Log $log - the underlying logger
*/
public function __construct(Log $log) {
if ($log == NULL) $log = Log::instance();
$this->log = $log;
}

/**
* @see \TgLog\Logger::warn()
*/
public function warn($s, $object = NULL) {
$this->log->logWarn($s, $object);
}

/**
* @see \TgLog\Logger::debug()
*/
public function debug($s, $object = NULL) {
$this->log->logDebug($s, $object);
}

/**
* @see \TgLog\Logger::error()
*/
public function error($s, $object = NULL) {
$this->log->logError($s, $object);
}

/**
* @see \TgLog\Logger::info()
*/
public function info($s, $object = NULL) {
$this->log->logInfo($s, $object);
}
}

38 changes: 38 additions & 0 deletions src/TgLog/Logger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace TgLog;

/**
* Interface to make it easier to integrate other log implementations.
*/
interface Logger {

/**
* Log the given string (and $object) in DEBUG level.
* @param string $s - the string to be logged
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
*/
public function debug(string $s, $object = NULL);

/**
* Log the given string (and $object) in DEBUG level.
* @param string $s - the string to be logged
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
*/
public function info(string $s, $object = NULL);

/**
* Log the given string (and $object) in WARN level.
* @param string $s - the string to be logged
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
*/
public function warn(string $s, $object = NULL);

/**
* Log the given string (and $object) in DEBUG level.
* @param string $s - the string to be logged
* @param mixed $object - an optional object that can be inspected (usually json-encoded in log)
*/
public function error(string $s, $object = NULL);

}
9 changes: 9 additions & 0 deletions src/TgUtils/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class Date extends \DateTime {
const MONTH_ABBR = "\x023\x03";
const MONTH_NAME = "\x024\x03";

/** Seconds per minute */
public const SECONDS_PER_MINUTE = 60;
/** Seconds per hour */
public const SECONDS_PER_HOUR = 3600;
/** Seconds per day */
public const SECONDS_PER_DAY = 86400;
/** Seconds per week */
public const SECONDS_PER_WEEK = 604800;

/**
* The format string to be applied when using the __toString() magic method.
*
Expand Down
Loading

0 comments on commit 92e2844

Please sign in to comment.