zozlak/logging

Set of methods to deal with the HTTP Accept header

Maintainers

πŸ‘ zozlak

Package info

github.com/zozlak/logging

pkg:composer/zozlak/logging

Statistics

Installs: 11 773

Dependents: 12

Suggesters: 0

Stars: 1

Open Issues: 0

1.2.0 2024-12-17 11:24 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 72ad79443745db1bce97fe34a2196781b04d845e

  • Mateusz Ε»Γ³Ε‚tak <zozlak.woop@zozlak.org>

This package is auto-updated.

Last update: 2026-06-26 17:37:00 UTC


README

πŸ‘ Latest Stable Version
πŸ‘ Build Status
πŸ‘ Coverage Status
πŸ‘ License

Logging

A simple file-based PSR-3 logging library.

  • provides basic severity level filtering
  • can be used as a singleton
    • also with multiple logs
  • able to serialize arrays and objects (first tries with __toString(), then applies json_encode())
  • supports placeholders (see PSR-3)
  • compatible with all PSR-3 releases from 1 on

Installation

composer require zozlak/logging

Usage

// simplest possible logging
$log = new \zozlak\logging\Log('log_file');
$log->info('message');

// logging to standard out/err
$log = new \zozlak\logging\Log('php://stdout');
$log->info('message');
$log = new \zozlak\logging\Log('php://stderr');
$log->info('message');

// logging to already opened file
$logFile = tmpfile();
$log = new \zozlak\logging\Log($logFile);
$log->info('message');

// message formatting and filtering
$log = new \zozlak\logging\Log('log_file', \Psr\Log\LogLevel::INFO, "{LEVEL}:{TIMESTAMP}:{FILE}:{LINE}:{MESSAGE}");
$log->info('message');
$log->debug('skipped message');

// singleton example
$log = new \zozlak\logging\Log('log_file');
\zozlak\logging\Logger::addLog($log);
\zozlak\logging\Logger::info('message');

// singleton with multiple logs
$logAll = new \zozlak\logging\Log('log_all');
$logErrors = new \zozlak\logging\Log('log_errors', \Psr\Log\LogLevel::ERROR);
\zozlak\logging\Logger::addLog($logAll, 'all');
\zozlak\logging\Logger::addLog($logErrors, 'error');

\zozlak\logging\Logger::info('message1', [], 'all');
\zozlak\logging\Logger::error('message2', [], 'error');
\zozlak\logging\Logger::error('message3'); // written to the 'error' log

\zozlak\logging\Logger::setDefaultLog('all');
\zozlak\logging\Logger::error('message4'); // written to the 'all' log