Convert Figma logo to code with AI

php-fig logolog

No description available

10,392
184
10,392
7

Top Related Projects

21,004

Sends your logs to files, sockets, inboxes, databases and various web services

Quick Overview

The php-fig/log repository is a PHP Standards Recommendation (PSR) for logging interfaces. It defines a common interface for logging libraries, allowing for interoperability between different logging implementations in PHP applications. This standard is part of the PHP Framework Interop Group (PHP-FIG) efforts to improve collaboration across PHP projects.

Pros

  • Promotes standardization and interoperability among logging libraries
  • Simplifies switching between different logging implementations
  • Encourages consistent logging practices across PHP projects
  • Widely adopted by popular PHP frameworks and libraries

Cons

  • Limited to basic logging functionality, may not cover all advanced use cases
  • Requires adoption by both library developers and application developers for full benefit
  • May introduce an additional layer of abstraction in some cases
  • Some existing logging libraries may require adaptation to conform to the standard

Code Examples

  1. Basic logging example:
use Psr\Log\LoggerInterface;

class MyClass
{
    private $logger;

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

    public function doSomething()
    {
        $this->logger->info('Doing something');
        // ... do something
    }
}
  1. Using different log levels:
$logger->emergency('System is down');
$logger->alert('Database connection failed');
$logger->critical('Unexpected error occurred');
$logger->error('Unable to process request');
$logger->warning('Deprecated function used');
$logger->notice('User logged in');
$logger->info('Processing started');
$logger->debug('Variable value: ' . $value);
  1. Logging with context:
$logger->error('User {username} not found', ['username' => 'john_doe']);

Getting Started

To use PSR-3 logging in your project:

  1. Install a PSR-3 compatible logger (e.g., Monolog):

    composer require monolog/monolog
    
  2. Create a logger instance:

    use Monolog\Logger;
    use Monolog\Handler\StreamHandler;
    
    $logger = new Logger('my_logger');
    $logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG));
    
  3. Use the logger in your code:

    $logger->info('Hello, PSR-3 logging!');
    

Competitor Comparisons

21,004

Sends your logs to files, sockets, inboxes, databases and various web services

Pros of Monolog

  • Comprehensive logging solution with numerous handlers and formatters
  • Extensive documentation and active community support
  • Flexible configuration options for various logging scenarios

Cons of Monolog

  • Larger codebase and potential overhead for simple logging needs
  • Steeper learning curve due to its extensive feature set

Code Comparison

Log (PSR-3 interface):

interface LoggerInterface
{
    public function log($level, $message, array $context = array());
}

Monolog implementation:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$log = new Logger('name');
$log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
$log->warning('Foo', ['bar' => 'baz']);

Summary

Log provides a standardized interface for logging libraries, while Monolog is a full-featured logging implementation. Log focuses on defining a common API, whereas Monolog offers a rich set of tools for various logging needs. Monolog implements the PSR-3 interface defined by Log, ensuring compatibility with other PSR-3 compliant systems.

While Monolog provides more functionality out of the box, it may be overkill for simple projects. Log's interface is ideal for creating custom, lightweight logging solutions or for projects that require a standardized logging approach across different libraries.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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:

<?php

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.