waza-ari / monolog-mysql

MySQL Handler for Monolog, which allows to store log messages to a MySQL Table
MIT License
141 stars 85 forks source link

Implicit committing may interrupt transactions #25

Closed egistli closed 1 year ago

egistli commented 7 years ago

First, thanks for the library, it's handy and doing well out-of-box.

However the CREATE TABLE IF NOT EXISTS... SQL in the initialize method may interrupt transactions unintentionally.

For the flow as following:

  1. beginTransaction
  2. execute some sql
  3. log with monolog-mysql
  4. rollback transaction

The rollback in step 4. will do nothing, because at step 3. the initialize method will be called and after the execution of SQL CREATE TABLE..., the transaction will be committed implicitly.

lpotherat commented 7 years ago

This class should be configurable to enable or disable dynamic structure changes to avoid this problem. This force to manage the table structure manually.

ghost commented 5 years ago

I have the same issue. As a result, just enabling this long handler in your app changes the way how the transactions are handled by the database engine. This happens implicitly and it is really tricky and difficult to debug. The easiest solution would be to have a constructor parameter initializeTable=true/false, if false then any DDL statements won't be executed.

amacado commented 1 year ago

There is already a constructor argument allowing to bypass the table initialization: $initialize or in the upcomming v2 $skipTableInitialization. See https://github.com/waza-ari/monolog-mysql/blob/master/src/MySQLHandler.php#L61