Sorry for the slow progress of this issue, but we have been busy trying to push the 2.1 release. We appreciate the work you put into this, but there is very few of us working on log4php at the moment.
I have seen your solution on github and I have taken most of the code from it. However, I think it has several issues.
Firstly, there are two appenders which are almost identical. LoggerAppenderMongoDBLayout and LoggerAppenderMongoDB. I understand what they do, but it seems unnecessary.
Secondly, the performance of LoggerAppenderMongoDBLayout is not optimal. When using it in combination with LoggerLayoutBson, the following happens:
- LoggerLoggingEventBsonifier converts the event to an array
- LoggerLayoutBson converts this array to json (includes converting the MongoDate object to timestamp)
- LoggerAppenderMongoDBLayout converts the json back into an array (includes converting the timestamp back to MongoDate)
The event is first converted to an array, then to json, then back to an array before it is finally logged. You will agree that this is not the best solution.
I think the best approach to this problem is to have one appender: LoggerAppenderMongoDB which does not use a layout (because layouts produce strings, and here we need an array). This appender can have a protected method which converts the logging event to an array (taken from LoggerLoggingEventBsonifier). If a user wishes to modify the format of the logged array, they can simply extend LoggerAppenderMongoDB and override that method.
I have created and commited the following changes to the repository:
- Moved the conversion code from LoggerLoggingEventBsonifier to LoggerAppenderMongoDB::format()
- Removed the LoggerLoggingEventBsonifier
- Merged the tests from LoggerLoggingEventBsonifierTest into LoggerAppenderMongoDBTest
I would appreciate if you would review them and see if this meets all your requirements.