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

Data should not be deleted when additional field is not provided anymore #11

Closed waza-ari closed 4 years ago

waza-ari commented 8 years ago

As pointed out in Pull Request #8 it is rather unintuitive that additional fields are deleted when not provided at class initialization. One example by FoxxMD:

What if I pushed two separate handlers with different additionalFields because I only wanted to include a subset of information on one handler? When that handler is initialized it would remove the missing columns and all my data!

There are two obvious ways:

  1. When new additionalFields are used, create the missing ones, but to not remove stale fields. Fill them with null if not provided (which is done anyway by now). They can still be deleted by hand
  2. Do not alter the table anyway. The user must create the logging table and specify which addionalFields can be used. If there are any addionalFields, which do not exist, then (2a) just ignore them or (2b) throw an exception.

Option 1 would give more flexibility, but option 2 maybe more stability plus the support for SQlite (see #8), as meta information need not to be queried from database.

What do you think?

cr-lgl commented 4 years ago

42