Skip to content

Commit

Permalink
A PSR-3 compliant logger with adjustable verbosity (#1)
Browse files Browse the repository at this point in the history
A [PSR-3](http://www.php-fig.org/psr/psr-3/) compliant logger with adjustable verbosity.
  • Loading branch information
WorkOfStan authored Jul 12, 2024
1 parent c681052 commit 5b66757
Show file tree
Hide file tree
Showing 17 changed files with 737 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# Set update schedule for GitHub Actions

version: 2
updates:
# See documentation for possible values
- package-ecosystem: "github-actions"
# Location of package manifests
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
41 changes: 41 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
###########################
###########################
## Markdown Linter rules ##
###########################
###########################

# Linter rules doc:
# - https://github.com/DavidAnson/markdownlint
#
# Note:
# To comment out a single error:
# <!-- markdownlint-disable -->
# any violations you want
# <!-- markdownlint-restore -->
#

############################
# Super-linter Rules by id #
############################
MD004: false # Unordered list style
MD007:
indent: 2 # Unordered list indentation
MD013:
line_length: 808 # Line length 80 is far too short
MD026:
punctuation: ".,;:!。,;:" # List of not allowed
MD029: false # Ordered list item prefix
MD033: false # Allow inline HTML
MD036: false # Emphasis used instead of a heading

##############################
# Super-linter Rules by tags #
##############################
blank_lines: false # Error on blank lines

########################
# Seablast Rules by id #
########################
# Multiple heading with the same content (in CHANGELOG.md)
MD024: false # No-duplicate-heading
35 changes: 35 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
###########################
###########################
## Linter GitHub Actions ##
###########################
###########################
name: Lint Code Base

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on:
push:
branches-ignore:
# notest branches to ignore testing of partial online commits
- 'notest/**'
pull_request:
branches-ignore:
# notest branches to ignore testing of partial online commits
- 'notest/**'

permissions:
contents: read

###############
# Set the Job #
###############
jobs:
call-workflow:
uses: WorkOfStan/seablast-actions/.github/workflows/linter.yml@main
18 changes: 18 additions & 0 deletions .github/workflows/overtrue-phplint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: PHP Linting (Overtrue)
on:
push:
branches-ignore:
# notest branches to ignore testing of partial online commits
- 'notest/**'
pull_request:
branches-ignore:
# notest branches to ignore testing of partial online commits
- 'notest/**'

permissions:
contents: read

jobs:
call-workflow:
uses: WorkOfStan/seablast-actions/.github/workflows/overtrue-phplint.yml@main
25 changes: 25 additions & 0 deletions .github/workflows/php-composer-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: PHP Composer + PHPUnit + PHPStan

on:
push:
branches-ignore:
# notest branches to ignore testing of partial online commits
- 'notest/**'

pull_request:
branches-ignore:
# notest branches to ignore testing of partial online commits
- 'notest/**'

permissions:
contents: read

jobs:
# Note: https://docs.github.com/en/actions/using-workflows/reusing-workflows The strategy property is not supported in any job that calls a reusable workflow.
call-workflow:
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
18 changes: 18 additions & 0 deletions .github/workflows/phpcbf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: PHPCBF
# ge-tracker/phpcbf-action can't handle branches with `/`
# `fatal: couldn't find remote ref` error is triggered
on:
push:
branches:
- 'phpcbf*'
pull_request:
branches:
- 'phpcbf*'

permissions:
contents: write

jobs:
call-workflow:
uses: WorkOfStan/seablast-actions/.github/workflows/phpcbf.yml@main
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#disable temporary and log files and dirs
*.log

#disable composer-managed libraries
/vendor/
#disable composer lock file
/composer.lock

#disable IDE files
/nbproject/
/.idea/
10 changes: 10 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# If mod_alias is not enabled, the Apache should fail to show anything in order to always hide the files in the section below
# nothing starting .git, i.e. also .github or .gitignore
RedirectMatch 404 /\.git
RedirectMatch 404 phpstan\.neon\.dist
RedirectMatch 404 phpunit\.xml
RedirectMatch 404 \.log$
RedirectMatch 404 \.md$
RedirectMatch 404 \.neon$
RedirectMatch 404 \.sh$
RedirectMatch 404 \.yml$
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### `Added` for new features

### `Changed` for changes in existing functionality

### `Deprecated` for soon-to-be removed features

### `Removed` for now removed features

### `Fixed` for any bugfixes

### `Security` in case of vulnerabilities

## [0.1] - 2024-07-12
- A PSR-3 compliant logger with adjustable verbosity based on Backyard\BackyardError

[Unreleased]: https://github.com/WorkOfStan/seablast-dist/compare/v0.1...HEAD
[0.1]: https://github.com/WorkOfStan/seablast-dist/releases/tag/v0.1
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
# seablast-logger
Logger compliant with PSR-3 http://www.php-fig.org/psr/psr-3/ and Tracy
A [PSR-3](http://www.php-fig.org/psr/psr-3/) compliant logger with adjustable verbosity.

The logging levels can be tailored to suit different environments.
For instance, in a development environment, the logger can be configured to log more detailed information compared to a production environment, all without changing your code.
Simply adjust the verbosity.

The `logging_level` is the most important setting. These parameters can be configured when instantiating the logger:
```php
$conf = array(
// 0 = send message to PHP's system logger; recommended is however 3, i.e. append to the file destination set in the field 'logging_file'
'error_log_message_type' => 0,
// if error_log_message_type equals 3, the message is appended to this file destination (path and name)
'logging_file' => '',
// log up to the level set here, default=5 = debug
'logging_level' => 5,
// rename or renumber, if needed
'logging_level_name' => array(0 => 'unknown', 1 => 'fatal', 'error', 'warning', 'info', 'debug', 'speed'),
// the logging level to which the page generation speed (i.e. error_number 6) is to be logged
'logging_level_page_speed' => 5,
// false => use logging_file with log extension as destination; true => adds .Y-m.log to the logging file
'log_monthly_rotation' => true,
// prefix message that took longer than profiling step (float) sec from the previous one by SLOWSTEP
'log_profiling_step' => false,
// fatal error may just be written in log, on production, it is however recommended to set an e-mail, where to announce fatal errors
'mail_for_admin_enabled' => false,
);
$logger = new Seablast\Logger\Logger($conf);
```
See [test.php](test.php) for usage.

By default the logger logs the following levels of information:
- fatal
- error
- warning
- info
- debug

And ignores
- speed

## Runtime adjustment
- method logAtLeastToLevel(int $level) may change the verbosity level above the level set when instatiating.
- method setUser(int|string $user) may add the user identification to the error messages

## Tracy\Logger::log wrapper
Since Nette\Tracy::v2.6.0, i.e. `"php": ">=7.1"` it is possible to use a PSR-3 adapter, allowing for integration of [seablast/logger](https://github.com/WorkOfStan/seablast-logger).

```php
$logger = new Seablast\Logger\Logger();
$tracyLogger = new Tracy\Bridges\Psr\PsrToTracyLoggerAdapter($logger);
Debugger::setLogger($tracyLogger);
Debugger::enable();
```
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "seablast/logger",
"description": "A PSR-3 compliant logger with adjustable verbosity.",
"type": "library",
"require": {
"php": "^5.3 || ^7.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"tracy/tracy": "^2.3.12"
},
"license": "MIT",
"authors": [
{
"name": "Stanislav Rejthar",
"email": "[email protected]"
}
],
"support": {
"email": "[email protected]",
"issues": "https://github.com/WorkOfStan/seablast-logger/issues",
"source": "https://github.com/WorkOfStan/seablast-logger"
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"autoload": {
"psr-4": {
"Seablast\\Logger\\": ["src/"]
}
}
}
7 changes: 7 additions & 0 deletions conf/phpstan.app.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 9
excludePaths:
analyse:
- ../vendor
scanDirectories:
- ../src
6 changes: 6 additions & 0 deletions conf/phpstan.webmozart-assert.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# The main configuration file in case `composer require --dev phpstan/phpstan-webmozart-assert` is used - makes difference if PHPStan level > 6
includes:
- phpstan.app.neon
# to use https://github.com/phpstan/phpstan-webmozart-assert
# phpstan/phpstan-webmozart-assert requires this settings
- ../vendor/phpstan/phpstan-webmozart-assert/extension.neon
7 changes: 7 additions & 0 deletions src/ErrorLogFailureException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Seablast\Logger;

class ErrorLogFailureException extends \Exception
{
}
Loading

0 comments on commit 5b66757

Please sign in to comment.