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

Columns channel, level, message and time are deleted #2

Closed CarlosLlongo closed 9 years ago

CarlosLlongo commented 9 years ago

Hi, When I started using monolog-mysql, I swear that all was working fine. But suddenly, no logs are being created. The problem is that only the additional fields are present in the database table. The channel, level, message and time columns are being deleted by this code:

$removedColumns = array_diff($actualFields, $this->additionalFields);

if (!empty($removedColumns)) foreach ($removedColumns as $c) {
    $this->pdo->exec('ALTER TABLE `'.$this->table.'` DROP `'.$c.'`;');
}

$actualFields are channel, level, message and time, and are not present in $this->additionalFiels, so of course they are stored in $removedColumns and deleted in the foreach loop.

Am I doing something wrong?

Thanks!

waza-ari commented 9 years ago

Hi Carlos,

looks weird. I am using this myself, and did not encounter this problem until now. If I look at the code, however, I think you must be right. $actualFields always contains all column names of the table, including channel, level, message and time. Following the logic of the code, they are simply removed every time the class is initialized.

I will try to reproduce this and provide a bug fix as soon as possible.

Thanks again for reporting the issue!

Best, Daniel

waza-ari commented 9 years ago

Hi Carlos,

sorry I did not came back earlier to the issue, I was quite busy in the meantime. However, I could confirm and fix the issue. Version 1.0.2 is now available both at GitHub and at composer and should fix the problem.

Regards Daniel