laminas / laminas-log

Robust, composite logger with filtering, formatting, and PSR-3 support
https://docs.laminas.dev/laminas-log/
BSD 3-Clause "New" or "Revised" License
26 stars 31 forks source link

Exception logging in MariaDb #36

Closed olivierbicler closed 2 years ago

olivierbicler commented 2 years ago

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.

laminas-bot commented 2 years ago

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

If you are looking for an actively maintained package alternative, we recommend:

Ocramius commented 2 years ago

Looks like the wrong platform was configured? The component does quoting based on the configured platform: https://github.com/laminas/laminas-log/blob/4f70c0c5db5066474a240635be188ce6d0337eb3/src/Writer/Db.php#L144

olivierbicler commented 2 years ago

Thanks for your response. As far I understood, this method returns quoteIdentifier attribute, which is hard coded : https://github.com/laminas/laminas-db/blob/42e842100ec56501eba4926abcdc57f6da2c9312/src/Adapter/Platform/Mysql.php#L19 protected $quoteIdentifier = ['', ''];

I'm obviously reluctant to alter code in Laminas, and I wonder if adding Mariadb as a new platform with the proper configuration would not be a nicer solution ? At this time, there is no mariadb platform configured in Laminas.

Ocramius commented 2 years ago

As you can see from your error message:

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

So it is using " instead of the MySQL backticks that you linked: this is because the Mysql platform is not in use at all in your scenario.

It's probably using the base platform: https://github.com/laminas/laminas-db/blob/42e842100ec56501eba4926abcdc57f6da2c9312/src/Adapter/Platform/Sql92.php