Giter Site home page Giter Site logo

laminas / laminas-log Goto Github PK

View Code? Open in Web Editor NEW
27.0 19.0 27.0 3.12 MB

Robust, composite logger with filtering, formatting, and PSR-3 support

Home Page: https://docs.laminas.dev/laminas-log/

License: BSD 3-Clause "New" or "Revised" License

PHP 99.99% HTML 0.01%
logger logging psr-3

laminas-log's Introduction

laminas-log

Build Status

🇷🇺 Русским гражданам

Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.

У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.

Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"

🇺🇸 To Citizens of Russia

We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.

One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.

You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"


Security-Only Maintenance Mode

This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering Committee. If you have a security issue, please follow our security reporting guidelines. If you wish to take on the role of maintainer, please nominate yourself

Laminas\Log is a component for general purpose logging. It supports multiple log backends, formatting messages sent to the log, and filtering messages from being logged.

Installation

Run the following to install this library:

$ composer require laminas/laminas-log

Documentation

Browse the documentation online at https://docs.laminas.dev/laminas-log/

Support

laminas-log's People

Contributors

akrabat avatar b-durand avatar bakura10 avatar dasprid avatar evandotpro avatar ezimuel avatar freeaqingme avatar jonathanmaron avatar koopzington avatar localheinz avatar macnibblet avatar maks3w avatar marc-mabe avatar michalbundyra avatar micheh avatar mikaelkael avatar mpinkston avatar mwillbanks avatar ocramius avatar prolic avatar ralphschindler avatar samsonasik avatar sgehrig avatar thinkscape avatar vahid-sohrabloo avatar veewee avatar waltertamboer avatar wdalmut avatar weierophinney avatar xerkus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laminas-log's Issues

Displaying writers logged events

Thanks for this standard logger library, currently using this logger to log events in wordpress and its working fine, though I'm majorly using just the "Stream" writer, I think there should be a beautiful way of displaying logged events from each writer. since all writers has a formatter, and these formatters implement the "Formatter" interface, there is a method "format" called when writing to logs, wouldnt it be beautiful to have "deformat" (dont mind the name) method that re-arrange/restyle the events when you want to display it, then each writer have a method "getErrorlogs" (again dont mind the name ), to show events logged in the writer class.

Already working on an implementation of this, just want to hear from you guys what you think


Originally posted by @rmoayinla at zendframework/zend-log#77

registerErrorHandler returns false

Hello, I noticed on my PHP 7.4.23 (running Ubuntu 20.04.3 LTS) the errors are not logged for Laminas Log so for testing I have disabled from the logger config:

'errorhandler' => true,
'exceptionhandler' => true,
'fatal_error_shutdownfunction' => true,

And rather I have set manually in onBootstrap:

$serviceManager = $e->getApplication()->getServiceManager();
$logger        = $serviceManager->get('appLog');

$result = \Laminas\Log\Logger::registerErrorHandler($logger);
$result2 = \Laminas\Log\Logger::registerFatalErrorShutdownFunction($logger);
$result3 = \Laminas\Log\Logger::registerExceptionHandler($logger);

$result is NULL, the rest are true.

It looks like the errors are not logged.

I debugged more and the: $previous is false so hence why returning false.

DB adapter does not allow schema

Just like other components, this one too is not designed to work with database schemas. It allows only to pass table name as string.
I suggest changing prepareInsert() method and config key 'table' to allow TableIdentifier or array.


Originally posted by @xorock at zendframework/zend-log#63

Documentation typo

Bug Report

Q A
Version(s) all

Summary

This line:
its elements will be translated as 'extra-field', where '-' is the character separator (default)

Current behavior

The default separator that is being used is an _ not a -

How to reproduce

Trying using the - as the default separator while writing a log to a table.

Expected behavior

That the docs include the correct default separator :)

Document all factories and plugin managers

The component includes a number of factories:

  • Factories:
    • Zend\Log\LoggerAbstractServiceFactory
    • Zend\Log\LoggerServiceFactory
  • Plugin Managers:
    • FilterPluginManager
    • FormatterPluginManager
    • ProcessorPluginManager
    • WriterPluginManager

Documentation should include how to setup configuration for each, and how additional plugins may be provided.


Originally posted by @weierophinney at zendframework/zend-log#26

Incorrect minimum version for PHP or wrong dependency for laminas/laminas-zendframework-bridge

Bug Report

Q A
Version(s) 2.5.1

Summary

I checked the packagist for the right version to use on my environment, a server with PHP 5.4.x.
According to the package list for laminas-laminas-log, version 2.5.1 should be compatible with PHP 5.4.
It states that the minimum version should be PHP: >=5.3.23.

But when targeting the project to use a PHP 5.4 environment, it causes a dependency unsatisfiable.
The problem is the dependency laminas/laminas-zendframework-bridge ^1.0, that requires PHP 5.6.
So, this dependency is wrong or the laminas-log minimum requirements are incorrect.

Current behavior

When executing the composer -W update command, it reports requirements not satisfiable.
Your requirements could not be resolved to an installable set of packages.

Problem 1
- laminas/laminas-zendframework-bridge[1.0.0, ..., 1.0.4] require php ^5.6 || ^7.0 -> your php version (5.4; overridden via config.platform, actual: 7.2.26) does not satisfy that requirement.
- laminas/laminas-zendframework-bridge[1.1.0, ..., 1.1.1] require php ^5.6 || ^7.0 || ^8.0 -> your php version (5.4; overridden via config.platform, actual: 7.2.26) does not satisfy that requirement.
- laminas/laminas-zendframework-bridge[1.2.0, ..., 1.3.0] require php ^7.3 || ^8.0 -> your php version (5.4; overridden via config.platform, actual: 7.2.26) does not satisfy that requirement.
- laminas/laminas-zendframework-bridge[1.4.0, ..., 1.4.1] require php ^7.3 || ~8.0.0 || ~8.1.0 -> your php version (5.4; overridden via config.platform, actual: 7.2.26) does not satisfy that requirement.
- laminas/laminas-zendframework-bridge[1.5.0, ..., 1.6.1] require php >=7.4, <8.2 -> your php version (5.4; overridden via config.platform, actual: 7.2.26) does not satisfy that requirement.
- laminas/laminas-zendframework-bridge 1.7.0 requires php ~8.0.0 || ~8.1.0 || ~8.2.0 -> your php version (5.4; overridden via config.platform, actual: 7.2.26) does not satisfy that requirement.
- laminas/laminas-log 2.5.1 requires laminas/laminas-zendframework-bridge ^1.0 -> satisfiable by laminas/laminas-zendframework-bridge[1.0.0, ..., 1.7.0].
- Root composer.json requires laminas/laminas-log 2.5.1 -> satisfiable by laminas/laminas-log[2.5.1].

How to reproduce

Expected behavior

Expected that composer could find a set of packages and update the project.

Undefined indexes and huge args-data in Zend\Log\Formatter\ExceptionHandler::format

A warning in advance: this can seriously crash your browser as it tries to write over 20.000 lines of code to the browser screen!

The notices the script produces:

Notice: Undefined index: file in D:\websites_assets\Zend-2.1.4dev\library\Zend\Log\Formatter\ExceptionHandler.php on line 43

Notice: Undefined index: line in D:\websites_assets\Zend-2.1.4dev\library\Zend\Log\Formatter\ExceptionHandler.php on line 44

SQL:

CREATE TABLE `_applicationlog` (
  `applicationlog_id` int(11) NOT NULL AUTO_INCREMENT,
  `log_date` datetime DEFAULT NULL,
  `message` text,
  `extra_file` varchar(300) DEFAULT NULL,
  `extra_line` varchar(10) DEFAULT NULL,
  `extra_trace` longtext,
  `priority` int(1) DEFAULT NULL,
  PRIMARY KEY (`applicationlog_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Module.php

<?php
namespace Log;

use Zend\Mvc\MvcEvent as MvcEvent;

class Module
{
    /**
     * On bootstrap event
     *
     * @access public
     * @param MvcEvent $event
     * @return void
     */
    public function onBootstrap(MvcEvent $event)
    {
        $application = $event->getApplication();
        $sm = $application->getServiceManager();

        $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
        $mapping = array(
            'timestamp'   => 'log_date',
            'message'     => 'message',
            'extra'       => array(
                'file'  => 'extra_file',
                'line'  => 'extra_line',
                'trace' => 'extra_trace',
            ),
            'priority'    => 'priority',
        );
        $writer = new \Zend\Log\Writer\Db($dbAdapter, '_applicationlog', $mapping);

        $formatter = new \Zend\Log\Formatter\ExceptionHandler();
        $formatter->setDateTimeFormat('Y-m-d H:i:s');
        $writer->setFormatter($formatter);

        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->registerExceptionHandler($logger);

        throw new \Exception('My custom message');
        return;
    }
}

Original issue: zendframework/zendframework#2592


Originally posted by @Martin-P at zendframework/zend-log#32

ExceptionHandler trace args size problem

Currently there is a problem with print_r in ExceptionHandler formatter, if argument is an object and not simple POCO / DTO but one that contains links to other objects and so on, it becomes very not trivial to dump exception message.

For example, with DoctrineModule, DoctrineORMModule configured in application if i make test exception throw in onBootstrap of module throw new Exception('Evil exception occured'); then the only argument of first trace will be MvcEvent but since it contains information about a lot of in application my memory limit is not enough to log exception, even 512 Mb not enough to log exception.

Possible solution:

would be greate to introduce to ExceptionHandler attribute like traceArgumentLevel that will dump object only to needed level as Doctrine2 Debug::dump does.

@Maks3w what your thoughs on this one?


Originally posted by @Ragazzo at zendframework/zend-log#16

Logger: fatal error shutdown

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7518
User: @ThaDafinser
Created On: 2015-05-13T09:08:48Z
Updated At: 2015-11-06T21:39:31Z
Body
If a fatal error comes up, the register_shutdown_function is called like wanted here:
https://github.com/zendframework/zf2/blob/master/library/Zend/Log/Logger.php#L617-L643

But the writers $writer->shutdown() function never gets called, so e.g. an eMail wont be send.
https://github.com/zendframework/zf2/blob/master/library/Zend/Log/Writer/Mail.php#L173



Originally posted by @GeeH at zendframework/zend-log#51

Exception logging in MariaDb

Bug Report

If I try to log something using Laminas library (embedded in Omeka S software), I end up with an exception (Omeka store logs in a database table).

Q A
Laminas Version(s) 2.6.0
Maria db version 10.5.9
Omeka S version 3.1.1

Summary

Current behavior

An exception is thrown

[Fri Apr 08 13:12:40.596256 2022] [php7:notice] [pid 17] [client 193.48.70.142:58478] PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '"log" ("created","severity","message","owner_id","context") VALUES ('2022-04-...' at line 1 in /var/www/html/vendor/laminas/laminas-db/src/Adapter/Driver/Pdo/Statement.php:238
Stack trace:
#0 /var/www/html/vendor/laminas/laminas-db/src/Adapter/Driver/Pdo/Statement.php(238): PDOStatement->execute()
#1 /var/www/html/vendor/laminas/laminas-log/src/Writer/Db.php(128): Laminas\\Db\\Adapter\\Driver\\Pdo\\Statement->execute(Array)
#2 /var/www/html/vendor/laminas/laminas-log/src/Writer/AbstractWriter.php(282): Laminas\\Log\\Writer\\Db->doWrite(Array)
#3 /var/www/html/vendor/laminas/laminas-log/src/Logger.php(459): Laminas\\Log\\Writer\\AbstractWriter->write(Array)
#4 /var/www/html/vendor/laminas/laminas-log/src/Logger.php(502): Laminas\\Log\\Logger->log(3, 'Exception: Noid...', Array)
#5 /var/www/html/application/src/Mvc/ExceptionListener.php(54): Laminas\\Log\\Logger->err('Exception: Noid...')
#6 /var/www/html/vendor/laminas/laminas-eventmanager/src/EventManager.php(321): Omeka\\Mvc\\ExceptionListener->handleException(Object(Laminas\\Mvc\\MvcEvent))
#7 /var/www/html/vendor/laminas/laminas-eventmanager/src/EventManager.php(170): Laminas\\EventManager\\EventManager->triggerListeners(Object(Laminas\\Mvc\\MvcEvent))
#8 /var/www/html/vendor/laminas/laminas-mvc/src/DispatchListener.php(153): Laminas\\EventManager\\EventManager->triggerEvent(Object(Laminas\\Mvc\\MvcEvent))
#9 /var/www/html/vendor/laminas/laminas-eventmanager/src/EventManager.php(321): Laminas\\Mvc\\DispatchListener->onDispatch(Object(Laminas\\Mvc\\MvcEvent))
#10 /var/www/html/vendor/laminas/laminas-eventmanager/src/EventManager.php(178): Laminas\\EventManager\\EventManager->triggerListeners(Object(Laminas\\Mvc\\MvcEvent), Object(Closure))
#11 /var/www/html/vendor/laminas/laminas-mvc/src/Application.php(331): Laminas\\EventManager\\EventManager->triggerEventUntil(Object(Closure), Object(Laminas\\Mvc\\MvcEvent))
#12 /var/www/html/index.php(21): Laminas\\Mvc\\Application->run()
#13 {main}

How to reproduce

Log any message.

Expected behavior

Log should be stored in database without any issue.

Identified causes and Workaround

This issue is caused because Mariadb only accepts backtick ` around identifiers by default. Double quote " needs to be specified in SQL_MODE (source) to be accepted. A way (the only way I found, actually) to get rid of this issue is to set SQL_MODE to ANSI_QUOTES.

Error and exception handlers doesn't call a previous handler

The previously defined error and exception handlers (if any) will be lost:
https://github.com/zendframework/zend-log/blob/master/src/Logger.php#L562
https://github.com/zendframework/zend-log/blob/master/src/Logger.php#L611

error_reporting(E_ALL);

set_error_handler(function () {
    // We will never get here :-(
    echo 'Previous error handler';
    return true;
});

$logger = new \Zend\Log\Logger([
    'exceptionhandler' => true,
    'errorhandler' => true,
    'writers' => [
        [
            'name' => 'Stream',
            'options' => [
                'stream' => './data/logs/' . date('Y-m-d') . '.log',
            ],
        ],
    ],
]);

trigger_error('Error', E_USER_ERROR);

Originally posted by @27cm at zendframework/zend-log#60

Psalm integration

Feature Request

Q A
QA yes

Summary

As decided during the Technical-Steering-Committee Meeting on August 3rd, 2020, Laminas wants to implement vimeo/psalm in all packages.

Implementing psalm is quite easy.

Required

  • Create a .psalm.xml.dist in the project root
  • Copy and paste the contents from this psalm.xml.dist
  • Run $ composer require vimeo/psalm
  • Run $ vendor/bin/psalm --set-baseline=psalm-baseline.xml
  • Add a composer script static-analysis with the command psalm --shepherd --stats
  • Add a new line to script: in .travis.yml: - if [[ $TEST_COVERAGE == 'true' ]]; then composer static-analysis ; fi
  • Remove phpstan from the project (phpstan.neon.dist, .travis.yml entry, composer.json require-dev and scripts)
Optional
  • Fix as many psalm errors as possible.

Add support for psr/log 2.x and 3.x

Feature Request

Q A
New Feature yes
RFC no
BC Break no?

Summary

Add support for psr/log 2.x and 3.x.
It should be possible to keep support for psr/log 1.x.

PHP 8.0 support

Feature Request

Q A
New Feature yes

Summary

To be prepared for the december release of PHP 8.0, this repository has some additional TODOs to be tested against the new major version.

In order to make this repository compatible, one has to follow these steps:

  • Modify composer.json to provide support for PHP 8.0 by adding the constraint ~8.0.0
  • Modify composer.json to drop support for PHP less than 7.3
  • Modify composer.json to implement phpunit 9.3 which supports PHP 7.3+
  • Modify .travis.yml to ignore platform requirements when installing composer dependencies (simply add --ignore-platform-reqs to COMPOSER_ARGS env variable)
  • Modify .travis.yml to add PHP 8.0 to the matrix (NOTE: Do not allow failures as PHP 8.0 has a feature freeze since 2020-08-04!)
  • Modify source code in case there are incompatibilities with PHP 8.0

Invalid PHPDoc-Block "@param string $message" in \Laminas\Log\Logger

Bug Report

Summary

The log-level specific methods like \Laminas\Log\Logger::alert are declared with a @param string $message PHPDoc-Block, which is wrong, as the \Laminas\Log\Logger::log method is declared with @param mixed $message.

Current behavior

Static code analysis tools like phpstan/phpstan report a error, if you call any of these methods with anything else than a string.

Expected behavior

All of the log-level specific methods are declared with a @param mixed $message PHPDoc-Block, like \Laminas\Log\Logger::log is.

Not able to udpate laminas-log to version 2.13.1

Hi Team,

not able to update laminas-log version from 2.12.1 to 2.13.1.

Current version is 2.12.1

and while update using composer I am seeing message "nothing to install or update"

My Current php version 7.4.18

Could you please let know If I am doing anything wrong ?

Cannot install package on a clean mezzio skeleton project

Bug Report

Q A
PHP 8.1
Composer 2.4.4

Summary

Cannot install package on a clean mezzio skeleton installation
laminas-log

Current behavior

composer shows "Your requirements could not be resolved to an installable set of packages." after command
composer require laminas/laminas-log

How to reproduce

create a fresh mezzio skeleton installation
then run
composer require laminas/laminas-log

Expected behavior

laminas-log installed

registerErrorHandler won't work unless you disable convertWriteErrorsToExceptions on the writer

Bug Report

Q A
Version(s) 2.12

Summary

Laminas\Log\Logger::registerErrorHandler wraps around set_error_handler. By default AbstractWriter starts Laminas\Stdlib\ErrorHandler before writing and stops it after. ErrorHandler's stop function in turn calls restore_error_handler. In practice this means that a very basic setup with a simple stream writer would not write any errors after the first one, since php error handler gets restored on the first write.

User can avoid this if he sets convertWriteErrorsToExceptions to false on the writer:

$writer->setConvertWriteErrorsToExceptions(false)

But this requires the user to first face this bug.

This bug is present since at least Zend 2.

Current behavior

Only one error gets written by the writer. After that Laminas\Log php error handler gets removed.

How to reproduce

Very basic one stream writer example would already suffer from this bug:

$logger = new Laminas\Log\Logger;
$writer = new Laminas\Log\Writer\Stream('/test.log');

$logger->addWriter($writer);
Laminas\Log\Logger::registerErrorHandler($logger);

$writer->setConvertWriteErrorsToExceptions(false);

trigger_error('test1');
trigger_error('test2');

Expected behavior

Ideally the ErrorHandler class should not call restore_error_handler and somehow remove only himself from the error handlers list. Unfortunately PHP does not have an API to do this.
The easiest fix is probably setting convertWriteErrorsToExceptions to false by default, but this brings back the reason why it converts errors to exceptions: now user has no way of knowing that his logging has failed.

Test failure since laminas/escaper 2.8

From Fedora CI
https://koschei.fedoraproject.org/package/php-laminas-log

Since laminas/escaper 2.8

1) LaminasTest\Log\Formatter\XmlTest::testFormatWillAcceptNestedArrayFromExtraEvent
TypeError: Argument 1 passed to Laminas\Escaper\Escaper::escapeHtml() must be of the type string, null given, called in /dev/shm/BUILDROOT/php-laminas-log-2.13.1-1.fc33.remi.x86_64/usr/share/php/Laminas/Log/Formatter/Xml.php on line 236

/usr/share/php/Laminas/Escaper/Escaper.php:180
/dev/shm/BUILDROOT/php-laminas-log-2.13.1-1.fc33.remi.x86_64/usr/share/php/Laminas/Log/Formatter/Xml.php:236
/dev/shm/BUILDROOT/php-laminas-log-2.13.1-1.fc33.remi.x86_64/usr/share/php/Laminas/Log/Formatter/Xml.php:192
/dev/shm/BUILD/laminas-log-6ac20830d4f324b4662fc454fcc1954436bfced3/test/Formatter/XmlTest.php:262

2) LaminasTest\Log\Formatter\XmlTest::testFormatWillEscapeAmpersand
TypeError: Argument 1 passed to Laminas\Escaper\Escaper::escapeHtml() must be of the type string, null given, called in /dev/shm/BUILDROOT/php-laminas-log-2.13.1-1.fc33.remi.x86_64/usr/share/php/Laminas/Log/Formatter/Xml.php on line 236

/usr/share/php/Laminas/Escaper/Escaper.php:180
/dev/shm/BUILDROOT/php-laminas-log-2.13.1-1.fc33.remi.x86_64/usr/share/php/Laminas/Log/Formatter/Xml.php:236
/dev/shm/BUILDROOT/php-laminas-log-2.13.1-1.fc33.remi.x86_64/usr/share/php/Laminas/Log/Formatter/Xml.php:192
/dev/shm/BUILD/laminas-log-6ac20830d4f324b4662fc454fcc1954436bfced3/test/Formatter/XmlTest.php:304

Json Formatter is missing in FormatterPluginManager

Bug Report

When configuring the Json Formatter via array the FormatterPluginManager cannot find the json formatter, because it is not registered in the plugin manager.

Q A
Version(s) 2.13.1

Summary

Current behavior

Exception is thrown:
"A plugin by the name "json" was not found in the plugin manager Laminas\Log\FormatterPluginManager"

How to reproduce

Not needed, I fixed it in the uploaded file.

Expected behavior

Logger instance that does Json formatting (file removed).

Simple formatter broken with non-array value extra array key in PHP > 8

Bug Report

Q A
Version(s) 2.15.1

Summary

Simple formatter broken with non-array value extra array key when using PHP version 8++.

How to reproduce

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => null,
        ];
        $formatter = new Simple();
        echo $formatter->format($fields);
        // Throws error: TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => '',
        ];
        $formatter = new Simple();

        echo $formatter->format($fields);
        // Throws error: TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given

Expected behavior

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => null,
        ];
        $formatter = new Simple();
        echo $formatter->format($fields);
        // Output: 2012-08-28T18:15:00+00:00 bar (42): foo

        $date   = new DateTime('2012-08-28T18:15:00Z');
        $fields = [
            'timestamp'    => $date,
            'message'      => 'foo',
            'priority'     => 42,
            'priorityName' => 'bar',
            'extra'        => '',
        ];

        $formatter = new Simple();
        echo $formatter->format($fields);
        // Output: 2012-08-28T18:15:00+00:00 bar (42): foo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.