PSR Log - This repository holds all interfaces/classes/traits related to PSR-3.

Related tags

Frameworks psr-3
Overview

PSR Log

This repository holds all interfaces/classes/traits related to PSR-3.

Note that this is not a logger of its own. It is merely an interface that describes a logger. See the specification for more details.

Installation

composer require psr/log

Usage

If you need a logger, you can use the interface like this:



use Psr\Log\LoggerInterface;

class Foo
{
    private $logger;

    public function __construct(LoggerInterface $logger = null)
    {
        $this->logger = $logger;
    }

    public function doSomething()
    {
        if ($this->logger) {
            $this->logger->info('Doing work');
        }
           
        try {
            $this->doSomethingElse();
        } catch (Exception $exception) {
            $this->logger->error('Oh no!', array('exception' => $exception));
        }

        // do something useful
    }
}

You can then pick one of the implementations of the interface to get a logger.

If you want to implement the interface, you can require this package and implement Psr\Log\LoggerInterface in your code. Please read the specification text for details.

Comments
  • Update LoggerInterfaceTest to be phpunit 5.7+ compatible

    Update LoggerInterfaceTest to be phpunit 5.7+ compatible

    \PHPUnit_Framework_TestCase does not exist in phpunit > 6

    For those who want a quick fix here is how you can do it: https://github.com/vanilla/vanilla/blob/19355f36e029cd26c01dfbc5823516ee537578a4/tests/phpunit.php#L5-L13

    opened by DaazKu 29
  • Update parameter and property types for version 2

    Update parameter and property types for version 2

    As per the upgrade bylaw.

    • Removes the long-outdated test classes. (This mandates a 2.0 release at least.)
    • Add parameter types.
    • Add one property type.
    • The spec very explicitly allows string|Stringable, so this requires PHP 8.0.
    • I also folded AbstractLogger and LoggerTrait together, since they're identical and there's no reason to support PHP 5.3 anymore. I am not certain if this should be considered kosher since AbstractLogger is specified in the spec. It's in its own commit so easy to undo if we decide to.
    opened by Crell 26
  • return types were incorrectly hinted as `null`, should be `void`

    return types were incorrectly hinted as `null`, should be `void`

    Corrected all return type-hints from null to void to avoid failed inspections in e.g. Php Storm.

    (strict inspection would state that a function must return if annotated with return null - as opposed to return void, which means the function does not use a return-statement and has no defined return-value.)

    opened by mindplay-dk 11
  • Remove illegal annotation

    Remove illegal annotation

    The @expectedException annotation is deprecated, and removed in PHPUnit 9. When testing with PHPUnit 8, the following warning appears for every time a logger test is run:

    The @expectedException, @expectedExceptionCode, @expectedExceptionMessage, and @expectedExceptionMessageRegExp annotations are deprecated. They will be removed in PHPUnit 9. Refactor your test to use expectException(), expectExceptionCode(), expectExceptionMessage(), or expectExceptionMessageMatches() instead.

    With PHPUnit 9.5.4, the tests fail with the following error:

    Inpsyde\WooCommerceLogging\Tests\Functional\AbstractLoggerTest::testThrowsOnInvalidLevel Psr\Log\InvalidArgumentException: Unknown log level "invalid level"

    /home/runner/work/product-woocommerce-logging/product-woocommerce-logging/src/AbstractLogger.php:42 /home/runner/work/product-woocommerce-logging/product-woocommerce-logging/vendor/psr/log/Psr/Log/Test/LoggerInterfaceTest.php:74

    opened by XedinUnknown 10
  • Add object as typehint for message

    Add object as typehint for message

    Every method accepts a string as the message, or an object with a __toString() method. Implementors MAY have special handling for the passed objects. If that is not the case, implementors MUST cast it to a string.

    Changes are made according to the above

    opened by gmponos 10
  • Safe LoggerAwareTrait

    Safe LoggerAwareTrait

    Moving a logger injection form the constructor to this trait can result in run time errors as opposed to build time errors. This change provides an error prone way to obtain the logger instance.

    opened by sergiuionescu 9
  • Return string from DummyTest::__toString

    Return string from DummyTest::__toString

    As stated in the PHP documentation the __toString has to return a string. Currently the DummyTest::__toString method doesn't comply with this and throws errors like this one in several of my PSR-3 releated packages.

    Returning a string from DummyTest::__toString as is expected by the language would solve those errors.

    opened by WyriHaximus 9
  • Add LoggerSpy

    Add LoggerSpy

    I'm opening this PR to ask if a class like this one would be welcome in this package: http://pastebin.com/AniQf8dw

    If the response if not a firm no, I can modify this PR to include a suitable version (no PHP-7, PSR-2 compliant, tests, ...) of that Spy.

    Rationale behind the Spy: just a regular Spy. Facilitates testing of classes using a logger. (In my case I'm testing some logging decorators.) Most people would do this via the PHPUnit mock API, though this has a number of problems/downsides compared to using a simple test double like this spy:

    • Breaks tools (rename refactoring, find usages, static code analysis) due to referring a method with a string
    • Unless doing something complicated will bind to if the production code calls log to a specific level such as error.
    • Requires a mocking framework, and developer knowledge of it
    opened by JeroenDeDauw 9
  • Make LoggerAwareTrait more helpful for integrating projects

    Make LoggerAwareTrait more helpful for integrating projects

    There are a couple of things that I have to do to every project I use with the psr logger aware interface and traits, and end up having to create duplicate code every time. It would be nice if we could improve the usefulness of the aware interface and trait.

    • Add a getLogger() method that defaults to NullLogger().
    • Return static from setLogger() to allow it to be chained.
    opened by davereid 9
  • Added throws annoation to log methods

    Added throws annoation to log methods

    PSR-3 clearly states that the log method MUST throw a Psr\Log\InvalidArgumentException if a level is given that is not known. However, the interface and the various base implementations are missing the corresponding @throws annotation. Consequently IDEs do not know that such an exception could be thrown. This PR is meant to fix this circumstance.

    Please note that I refrained from adding any additional documentation to the annotation, simply because everything else is completely undocumented as well.

    opened by Fleshgrinder 8
  • Fixes #8: PSR-3 claims to follow RFC 5424 but LogLevel constants do not.

    Fixes #8: PSR-3 claims to follow RFC 5424 but LogLevel constants do not.

    PSR-3 claims to use RFC 5424 log levels:

    The LoggerInterface exposes eight methods to write logs to the eight RFC 5424 levels (debug, info, notice, warning, error, critical, alert, emergency).

    Problem: The log message severity levels are defined as strings, which causes PSR-3 to violate RFC 5424.

    http://tools.ietf.org/html/rfc5424#section-6.2.1 clearly defines:

        Numerical         Severity
          Code
           0       Emergency: system is unusable
           1       Alert: action must be taken immediately
           2       Critical: critical conditions
           3       Error: error conditions
           4       Warning: warning conditions
           5       Notice: normal but significant condition
           6       Informational: informational messages
           7       Debug: debug-level messages
    
           Table 2. syslog Message Severities
    

    RFC 5424 is the successor of RFC 3164. The IETF standard for log message severities exists since 2001.

    It's not clear why PSR-3 was entirely modeled after RFC 5424, and even includes literal copies of text fragments, but suddenly diverges from it in LogLevel constant values.

    As discussed here this causes PSR-3 to not meet the goal of interoperability (it's primary objective).

    I can see two options:

    A. Change the constant values to adhere to RFC 5424. (code change) B. Stop pretending that PSR-3 has anything to do with RFC 5424. (textual spec change)


    (Incomplete) List of projects that are following the IETF standard:

    Out of all other analyzed projects, most are using custom integers (e.g., Monolog, Joomla, Mediawiki).

    Excluding the (1-2) projects that migrated to PSR-3 already, this research yielded only 1-2 projects using strings (Yii Framework + another I forgot to record).

    opened by sun 7
Releases(1.1.4)
Owner
PHP-FIG
PHP-FIG
This repository contains custom View classes for the template frameworks

Slim Views This repository contains custom View classes for the template frameworks listed below. You can use any of these custom View classes by eith

Slim Framework 308 Nov 7, 2022
XStatic is a PHP library for enabling static proxy interfaces

XStatic is a PHP library for enabling static proxy interfaces—similar to Laravel 4+ "Facades"—but with any PHP project. XStatic was created by Jeremy Lindblom.

Jeremy Lindblom 104 Dec 8, 2022
📦 This is a repository of centralized management of all swoft core components

Swoft Component This repository is used to manage all swoft core components. 中文说明 中文说明请查看 README.zh-CN.md IMPORTANT All components will NOT be modifie

Swoft Cloud 95 Nov 16, 2022
Multi-process coroutine edition Swoole spider !! Learn about Swoole's network programming and the use of its related APIs

swoole_spider php bin/spider // Just do it !! Cache use Swoole\Table; use App\Table\Cache; $table = new Table(1<<20); // capacity size $table->column

null 3 Apr 22, 2021
Log with Cloudwatch

Yii2 Cloudwatch Logs Target Working in 2021 This is a fork from Codemonauts but fixed with some pr of other users. A Yii2 log target for AWS Cloudwatc

E.Alamo 1 Nov 25, 2021
Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container, http, log and route.

Kit What is it Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container,

null 2 Sep 23, 2022
Domain Driven Design PHP helper classes

carlosbuenosvinos/ddd This library will help you with typical DDD scenarios, for now: Application Services Interface Transactional Application Service

Domain-Driven Design in PHP 642 Dec 28, 2022
PHPneeds library (classes) package.

PHPneeds is a lightweight non-MVC PHP library for quickly start a project. About PHPneeds library (classes) package. Please use with PHPneeds base pro

PHPneeds 2 Oct 21, 2021
Provides database storage and retrieval of application settings, with a fallback to the config classes.

Provides database storage and retrieval of application settings, with a fallback to the config classes.

CodeIgniter 4 web framework 47 Dec 29, 2022
CakePHP: The Rapid Development Framework for PHP - Official Repository

CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Associative Data Mapping, Front Controller, and MVC. O

CakePHP 8.6k Dec 31, 2022
Official Zend Framework repository

Welcome to the Zend Framework 3.0 Release! RELEASE INFORMATION Zend Framework 3.0.1dev This is the first maintenance release for the Zend Framework 3

Zend Framework 5.6k Dec 29, 2022
This package provides some basic methods to implement a self updating functionality for your Laravel application. Already bundled are some methods to provide a self-update mechanism via Github or some private repository via http.

This package provides some basic methods to implement a self updating functionality for your Laravel 5 application. Already bundled are some methods to provide a self-update mechanism via Github.

Holger Lösken 311 Dec 31, 2022
This repository include my own PHP MVC Framework

PHP OWN MVC FRAMEWORK Kendimi geliştirmek ve modern PHP Framework'lerinin işleyişini kavram amacıyla inşa ettiğim profesyonele yakın PHP MVC Framework

Yılmaz Kadan 9 Nov 24, 2022
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 45 Nov 29, 2022
This repository contains a library of optional middleware for your Slim Framework application

Slim Framework Middleware This repository contains a library of optional middleware for your Slim Framework application. How to Install Update your co

Slim Framework 47 Nov 7, 2022
A skeleton repository for Spatie's PHP Packages

:package_description This package can be used as to scaffold a framework agnostic package. Follow these steps to get started: Press the "Use template"

Spatie 335 Dec 25, 2022
It validates PSR-7 messages (HTTP request/response) against OpenAPI specifications

NOTICE - THE PACKAGE HAS BEEN CONTRIBUTED TO THE PHP LEAGUE Go to https://github.com/thephpleague/openapi-psr7-validator This package is here for exis

Dmitry Lezhnev 167 Sep 29, 2022
PSR-15 Adapter for InertiaJS

inertia-psr15 Before using this library, is important to know what is Inertia.js, what is it for and how it works, in the official Inertia.js website

Mohamed Cherif Bouchelaghem 28 Oct 26, 2022
PSR-7 HTTP message library

PSR-7 Message Implementation This repository contains a full PSR-7 message implementation, several stream decorators, and some helpful functionality l

Guzzle 7.6k Jan 4, 2023