Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 24 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
name: CI

on: [push]
on:
push:
pull_request:

permissions:
contents: read
actions: read

jobs:
composer:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 8.1, 8.2, 8.3, 8.4 ]
php: [ 8.2, 8.3, 8.4, 8.5 ]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Cache Composer dependencies
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}

- uses: php-actions/composer@v6
- name: Composer install
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php }}
php_extensions: pcntl

- name: Archive build
run: mkdir /tmp/github-actions/ && tar --exclude=".git" -cvf /tmp/github-actions/build.tar ./
Expand All @@ -30,13 +38,14 @@ jobs:
with:
name: build-artifact-${{ matrix.php }}
path: /tmp/github-actions
retention-days: 1

phpunit:
runs-on: ubuntu-latest
needs: [composer]
needs: [ composer ]
strategy:
matrix:
php: [ 8.1, 8.2, 8.3, 8.4 ]
php: [ 8.2, 8.3, 8.4, 8.5 ]

outputs:
coverage: ${{ steps.store-coverage.outputs.coverage_text }}
Expand All @@ -51,11 +60,10 @@ jobs:
run: tar -xvf /tmp/github-actions/build.tar ./

- name: PHP Unit tests
uses: php-actions/phpunit@v3
uses: php-actions/phpunit@v4
env:
XDEBUG_MODE: cover
with:
version: 10
php_version: ${{ matrix.php }}
php_extensions: xdebug
coverage_text: _coverage/coverage.txt
Expand All @@ -72,7 +80,7 @@ jobs:
needs: [ phpunit ]
strategy:
matrix:
php: [ 8.1, 8.2, 8.3, 8.4 ]
php: [ 8.2, 8.3, 8.4, 8.5 ]

steps:
- uses: actions/checkout@v4
Expand All @@ -86,17 +94,17 @@ jobs:
run: cat "_coverage/coverage.txt"

- name: Upload to Codecov
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: PhpGt/Logger
slug: ${{ github.repository }}

phpstan:
runs-on: ubuntu-latest
needs: [composer]
needs: [ composer ]
strategy:
matrix:
php: [ 8.1, 8.2, 8.3, 8.4 ]
php: [ 8.2, 8.3, 8.4, 8.5 ]

steps:
- uses: actions/download-artifact@v4
Expand All @@ -112,19 +120,5 @@ jobs:
with:
php_version: ${{ matrix.php }}
path: src/


remove_old_artifacts:
runs-on: ubuntu-latest

steps:
- name: Remove old artifacts for prior workflow runs on this repository
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api "/repos/${{ github.repository }}/actions/artifacts" | jq ".artifacts[] | select(.name | startswith(\"build-artifact\")) | .id" > artifact-id-list.txt
while read id
do
echo -n "Deleting artifact ID $id ... "
gh api --method DELETE /repos/${{ github.repository }}/actions/artifacts/$id && echo "Done"
done <artifact-id-list.txt
level: 6
memory_limit: 256M
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Simple logger for PHP applications.
===================================

Start logging with zero configuration. By default, the logger works as a static singleton - `Log::error("You can't do that");` is all you need to get started. When you need to, you can configure the logger to send logs to different file/socket sources.
Start logging with zero configuration. By default, the logger writes to standard output, so `Log::error("You can't do that");` is all you need to get started. When you need to, you can configure the logger to send logs to different file or stream sources.

The aim of this library is minimalism. There are no plans to implement more logging sources than files and sockets. This simplifies the code into having a single responsibility, but remains modular to hook up to external scripts that handle logging to email addresses, Slack messages, AWS SQS, databases, etc.
The aim of this library is minimalism. There are no large configuration objects or transport layers to learn first. We get a set of familiar log levels, a small handler system, and a straightforward way to route messages where they need to go.

Log levels
----------

This library implements the [PSR-3 interface][psr3]. This means that throughout your code, you can decide to log at the levels listed below, and your environment can decide the minimum log level to report. For instance, it would probably be too verbose to log debug information on a production server. This is consistent with the [Syslog protocol][syslog].
This library uses the standard [PSR-3][psr3] level names. This means that throughout your code, you can decide to log at the levels listed below, and your environment can decide the minimum log level to report. For instance, it would probably be too verbose to log debug information on a production server. This is consistent with the [Syslog protocol][syslog].

+ `debug` - Detailed debugging information.
+ `info` - Interesting events.
Expand All @@ -19,25 +19,21 @@ This library implements the [PSR-3 interface][psr3]. This means that throughout
+ `alert` - Action must be taken immediately.
+ `emergency` - System is unusable.

Static usage
------------
Basic usage
-----------

[Static classes should only be used when truly stateless][styleguide-static]. Logging is one example of a class that has no side effects on the running program, so the primary usage expectation is to use static methods of the `Log` class to perform logging.

It would be unnecessary to require passing an instance of the `Log` class around throughout all classes of your program, and it would be too opinionated to require the use of a dependency injection framework everywhere that logging is possible.

However, certain programs require advanced logging features that are only satisfiable with instances of the `Log` class, such as having different log sources for different areas of the program. Take a look at the [examples directory][examples] to see how instantiation can be used for this purpose.
The primary entry point is the static `Log` class. Configure handlers near the start of the application, then call the matching log-level method whenever you need it.

Usage example
-------------

```php
use Gt\Logger\Log;
use Gt\Logger\LogConfig;
use Gt\Logger\LogLevel;
use Gt\Logger\LogHandler\StreamHandler;
use Gt\Logger\LogHandler\FileHandler;
use Gt\Logger\LogHandler\StdErrHandler;
use GT\Logger\Log;
use GT\Logger\LogConfig;
use GT\Logger\LogLevel;
use GT\Logger\LogHandler\StreamHandler;
use GT\Logger\LogHandler\FileHandler;
use GT\Logger\LogHandler\StdErrHandler;

// Send warnings and above to the remote socket.
LogConfig::addHandler(new StreamHandler("/example/remote.sock"), LogLevel::WARNING);
Expand Down Expand Up @@ -65,10 +61,11 @@ else {
}
```

[styleguide-static]: https://github.com/PhpGt/StyleGuide/blob/master/classes/members.md#classes-should-have-all-or-no-static-members
The primary namespace is `GT\Logger`. The legacy `Gt\Logger` classes remain autoloadable for backwards compatibility.

Full documentation is available in the wiki: https://github.com/PhpGt/Logger/wiki
[psr3]: https://www.php-fig.org/psr/psr-3/
[syslog]: https://tools.ietf.org/html/rfc5424
[examples]: https://github.com/PhpGt/Logger/tree/master/examples

# Proudly sponsored by

Expand Down
16 changes: 13 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,35 @@
"authors": [
{
"name": "Greg Bowler",
"email": "greg.bowler@g105b.com"
"email": "greg@g105b.com"
}
],

"autoload": {
"psr-4": {
"GT\\Logger\\": "./src",
"Gt\\Logger\\": "./src"
}
},
"autoload-dev": {
"psr-4": {
"Gt\\Logger\\Test\\": "./test/phpunit"
"GT\\Logger\\Test\\": "./test/phpunit"
}
},

"scripts": {
"phpunit": "vendor/bin/phpunit --configuration phpunit.xml",
"phpstan": "vendor/bin/phpstan analyse --level 6 src --memory-limit 256M",
"test": [
"@phpunit",
"@phpstan"
]
},

"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/PhpGt"
"url": "https://github.com/sponsors/phpgt"
}
]
}
Loading
Loading