Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.54 KB

log.md

File metadata and controls

51 lines (39 loc) · 1.54 KB
notice title description image permalink source layout
This file is imported and can be edited at https://github.com/amphp/log/blob/2.x/README.md
Non-blocking Logging in PHP
Learn how to write logs for your application in a non-blocking way.
undraw/undraw_diary.svg
/log
docs

AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. amphp/log provides a non-blocking stream handler for monolog/monolog.

Release License

Installation

This package can be installed as a Composer dependency.

composer require amphp/log

Usage

<?php

use Amp\ByteStream;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Monolog\Logger;

require dirname(__DIR__) . '/vendor/autoload.php';

// You can also log to a file using amphp/file:
// $handler = new StreamHandler(File\openFile(__DIR__ . '/example.log', 'w'));

// Here we'll log to the standard output stream of the current process:
$handler = new StreamHandler(ByteStream\getStdout());
$handler->setFormatter(new ConsoleFormatter);

$logger = new Logger('main');
$logger->pushHandler($handler);

$logger->debug("Hello, world!");
$logger->info("Hello, world!");
$logger->notice("Hello, world!");
$logger->error("Hello, world!");
$logger->alert("Hello, world!");