Skip to content

Commit

Permalink
Stable version for PHP/7.1+ || PHP/8.x (#4)
Browse files Browse the repository at this point in the history
- A [PSR-3](https://www.php-fig.org/psr/psr-3/) compliant logger with adjustable verbosity (based on Backyard\BackyardError).
-  Class configuration is managed by an array where field names are defined as constants to enable IDE hints.
- Stable version for `"php": "^7.1 || ^8.0"`.
  • Loading branch information
WorkOfStan authored Jul 27, 2024
1 parent 97171d6 commit c916f6c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/php-composer-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ jobs:
uses: WorkOfStan/seablast-actions/.github/workflows/php-composer-dependencies-reusable.yml@main
with:
# JSON
php-version: '["5.3", "5.4", "5.5", "5.6", "7.0", "7.1", "7.2", "7.3", "7.4"]'
# TODO: add , "8.0", "8.1", "8.2", "8.3" when 5.x removed
php-version: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]'
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### `Security` in case of vulnerabilities

## [2.0] - 2024-07-27
Stable version for `"php": "^7.1 || ^8.0"`. (As of PHP 7.1.0 visibility modifiers are allowed for class constants.)

## [1.0] - 2024-07-27
Stable version for `"php": "^5.3 || ^7.0"`

Expand All @@ -30,7 +33,8 @@ Stable version for `"php": "^5.3 || ^7.0"`
## [0.1] - 2024-07-12
- A [PSR-3](https://www.php-fig.org/psr/psr-3/) compliant logger with adjustable verbosity (based on Backyard\BackyardError)

[Unreleased]: https://github.com/WorkOfStan/seablast-logger/compare/v1.0...HEAD
[Unreleased]: https://github.com/WorkOfStan/seablast-logger/compare/v2.0...HEAD
[2.0]: https://github.com/WorkOfStan/seablast-logger/compare/v1.0...v2.0
[1.0]: https://github.com/WorkOfStan/seablast-logger/compare/v0.2...v1.0
[0.2]: https://github.com/WorkOfStan/seablast-logger/compare/v0.1...v0.2
[0.1]: https://github.com/WorkOfStan/seablast-logger/releases/tag/v0.1
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"description": "A PSR-3 compliant logger with adjustable verbosity.",
"type": "library",
"require": {
"php": "^5.3 || ^7.0",
"php": "^7.1 || ^8.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"tracy/tracy": "^2.3.12"
"tracy/tracy": "^2.6.0"
},
"license": "MIT",
"authors": [
Expand Down
44 changes: 20 additions & 24 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@
class Logger extends AbstractLogger implements LoggerInterface
{
// Define constants for configuration keys
// phpcs:disable PSR12.Properties.ConstantVisibility.NotFound
// todo remove phpcs exception when PHP/5 support removed
const CONF_ERROR_LOG_MESSAGE_TYPE = 'error_log_message_type';
const CONF_LOGGING_FILE = 'logging_file';
const CONF_LOGGING_LEVEL = 'logging_level';
const CONF_LOGGING_LEVEL_NAME = 'logging_level_name';
const CONF_LOGGING_LEVEL_PAGE_SPEED = 'logging_level_page_speed';
const CONF_LOG_MONTHLY_ROTATION = 'log_monthly_rotation';
const CONF_LOG_PROFILING_STEP = 'log_profiling_step';
const CONF_MAIL_FOR_ADMIN_ENABLED = 'mail_for_admin_enabled';
// phpcs:enable
public const CONF_ERROR_LOG_MESSAGE_TYPE = 'error_log_message_type';
public const CONF_LOGGING_FILE = 'logging_file';
public const CONF_LOGGING_LEVEL = 'logging_level';
public const CONF_LOGGING_LEVEL_NAME = 'logging_level_name';
public const CONF_LOGGING_LEVEL_PAGE_SPEED = 'logging_level_page_speed';
public const CONF_LOG_MONTHLY_ROTATION = 'log_monthly_rotation';
public const CONF_LOG_PROFILING_STEP = 'log_profiling_step';
public const CONF_MAIL_FOR_ADMIN_ENABLED = 'mail_for_admin_enabled';

/** @var array<mixed> int,string,bool,array */
protected $conf = array();
Expand Down Expand Up @@ -91,7 +88,7 @@ public function __construct(array $conf = array(), LoggerTime $time = null)
* @param int $newLevel
* @return void
*/
public function logAtLeastToLevel(int $newLevel)
public function logAtLeastToLevel(int $newLevel): void
{
if (!is_int($newLevel)) {
throw new \Psr\Log\InvalidArgumentException('The variable $newLevel is not an integer.');
Expand All @@ -102,7 +99,7 @@ public function logAtLeastToLevel(int $newLevel)
/**
* @return float
*/
public function getLastRunningTime()
public function getLastRunningTime(): float
{
return $this->runningTime;
}
Expand All @@ -113,7 +110,7 @@ public function getLastRunningTime()
* @param int|string $user
* @return void
*/
public function setUser($user)
public function setUser($user): void
{
$this->user = (string) $user;
}
Expand All @@ -125,9 +122,8 @@ public function setUser($user)
* @param array<int> $context
* @return void
*/
public function emergency($message, array $context = array())
public function emergency($message, array $context = array()): void
{
//TODO when adding PHP/8 support, add :void to the inherited methods and remove PHP/5 support
$this->log(0, $message, $context);
}

Expand All @@ -141,7 +137,7 @@ public function emergency($message, array $context = array())
* @param array<int> $context
* @return void
*/
public function alert($message, array $context = array())
public function alert($message, array $context = array()): void
{
$this->log(1, $message, $context);
}
Expand All @@ -155,7 +151,7 @@ public function alert($message, array $context = array())
* @param array<int> $context
* @return void
*/
public function critical($message, array $context = array())
public function critical($message, array $context = array()): void
{
$this->log(1, $message, $context);
}
Expand All @@ -168,7 +164,7 @@ public function critical($message, array $context = array())
* @param array<int> $context
* @return void
*/
public function error($message, array $context = array())
public function error($message, array $context = array()): void
{
$this->log(2, $message, $context);
}
Expand All @@ -183,7 +179,7 @@ public function error($message, array $context = array())
* @param array<int> $context
* @return void
*/
public function warning($message, array $context = array())
public function warning($message, array $context = array()): void
{
$this->log(3, $message, $context);
}
Expand All @@ -195,7 +191,7 @@ public function warning($message, array $context = array())
* @param array<int> $context
* @return void
*/
public function notice($message, array $context = array())
public function notice($message, array $context = array()): void
{
$this->log(4, $message, $context);
}
Expand All @@ -209,7 +205,7 @@ public function notice($message, array $context = array())
* @param array<int> $context
* @return void
*/
public function info($message, array $context = array())
public function info($message, array $context = array()): void
{
$this->log(4, $message, $context);
}
Expand All @@ -221,7 +217,7 @@ public function info($message, array $context = array())
* @param array<int> $context
* @return void
*/
public function debug($message, array $context = array())
public function debug($message, array $context = array()): void
{
$this->log(5, $message, $context);
}
Expand Down Expand Up @@ -265,7 +261,7 @@ public function debug($message, array $context = array())
* 1001 Establish correct error_number
*
*/
public function log($level, $message, array $context = array())
public function log($level, $message, array $context = array()): void
{
//TODO add variable $line - it should always be called as basename(__FILE__)."#".__LINE__ ,
//so it's clear which line of the source code triggered the call
Expand Down

0 comments on commit c916f6c

Please sign in to comment.