laminas / laminas-log Goto Github PK
View Code? Open in Web Editor NEWRobust, 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
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
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
Fatal error: Maximum function nesting level of '100' reached, aborting! in ../library/zendframework/zend-log/src/LoggerAbstractServiceFactory.php on line 85
Problem resolve when we put a "Config" on $services->has('config') line 91...
Originally posted by @nsantosMyt at zendframework/zend-log#34
Q | A |
---|---|
Version(s) | 2.15.1 |
Simple formatter broken with non-array value extra array key when using PHP version 8++.
$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
$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
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
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 ?
Q | A |
---|---|
New Feature | yes |
RFC | no |
BC Break | no? |
Add support for psr/log 2.x and 3.x.
It should be possible to keep support for psr/log 1.x.
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
Q | A |
---|---|
Version(s) | all |
This line:
its elements will be translated as 'extra-field', where '-' is the character separator (default)
The default separator that is being used is an _ not a -
Trying using the - as the default separator while writing a log to a table.
That the docs include the correct default separator :)
Q | A |
---|---|
Version(s) | 2.5.1 |
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.
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].
Expected that composer could find a set of packages and update the project.
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
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.
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
Q | A |
---|---|
Version(s) | 2.12 |
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.
Only one error gets written by the writer. After that Laminas\Log php error handler gets removed.
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');
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.
Q | A |
---|---|
QA | yes |
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.
.psalm.xml.dist
in the project root$ composer require vimeo/psalm
$ vendor/bin/psalm --set-baseline=psalm-baseline.xml
static-analysis
with the command psalm --shepherd --stats
script:
in .travis.yml
: - if [[ $TEST_COVERAGE == 'true' ]]; then composer static-analysis ; fi
phpstan.neon.dist
, .travis.yml
entry, composer.json
require-dev
and scripts
)https://github.com/laminas/laminas-log/runs/6223336132?check_suite_focus=true#step:3:11
@weierophinney or @Xerkus can you help here?
Thanks in advance!
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 |
Exception is thrown:
"A plugin by the name "json" was not found in the plugin manager Laminas\Log\FormatterPluginManager"
Not needed, I fixed it in the uploaded file.
Logger instance that does Json formatting (file removed).
Hey,
is there any information or discussion about implementing the PSR-3 standard for Logger (https://github.com/php-fig/log). We often have this problem (like using also Monolog Logger).
If not we will laminas-log and replace it with another framework.
Best regards, David
The component includes a number of factories:
Zend\Log\LoggerAbstractServiceFactory
Zend\Log\LoggerServiceFactory
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
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
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 |
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}
Log any message.
Log should be stored in database without any issue.
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.
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
.
Static code analysis tools like phpstan/phpstan
report a error, if you call any of these methods with anything else than a string
.
All of the log-level specific methods are declared with a @param mixed $message
PHPDoc-Block, like \Laminas\Log\Logger::log
is.
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
Q | A |
---|---|
New Feature | yes |
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:
composer.json
to provide support for PHP 8.0 by adding the constraint ~8.0.0
composer.json
to drop support for PHP less than 7.3composer.json
to implement phpunit 9.3 which supports PHP 7.3+.travis.yml
to ignore platform requirements when installing composer dependencies (simply add --ignore-platform-reqs
to COMPOSER_ARGS
env variable).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!)Q | A |
---|---|
PHP | 8.1 |
Composer | 2.4.4 |
Cannot install package on a clean mezzio skeleton installation
composer shows "Your requirements could not be resolved to an installable set of packages." after command
composer require laminas/laminas-log
create a fresh mezzio skeleton installation
then run
composer require laminas/laminas-log
laminas-log installed
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.