Added MongoDB log writer#1825
Conversation
There was a problem hiding this comment.
Ha, I was testing whether any() still complained if an expectation was never invoked. It only happened in conjunction with with(), but recent version of PHPUnit must have resolved the bug.
|
Can you adapt the file headers (http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files)? |
|
Will do when I'm back in the office tomorrow morning. |
|
@jmikola Nice, thanks :) What is the benefit between convert DateTime to ISO and MongoDates? We need to add a Formater to format the data (dates, ...). I will review that component soon. |
|
@b-durand: Essentially the same reason you'd want a date column type in SQL. Converting to a MongoDate will let you work with the value as a date object for querying or, better yet, the aggregation framework (for generating reports and doing log analysis). Is there any documentation about the structure of the |
|
@Maks3w: I updated the doc headers. Can you review? |
|
@ezimuel Could you do the final review of this PR? |
|
@jmikola The format of $event is this: https://github.com/zendframework/zf2/blob/master/library/Zend/Log/Logger.php#L285 |
|
@Maks3w: Thanks. Looking at the Logger code, I think the responsibility of date formatting fall on the Writer class, which may or may not elect to use some functionality in a formatter. For a DB-based logger, that's really the only way you'll be able to properly record a log entry's timestamp in the appropriate field type. |
There was a problem hiding this comment.
The message of exception can be more explicit like MongoCollection can be empty or must be defined.
|
If you need to format the event (array), you need to define a Formatter to solve type problem like date or scalar. You should have a separation of concerns : writer knows how send event to a backend, and formatter processes data to validate the "rules" of the backend. You open a way to use DateTime (as default), or MongoDate if you have an advantage. |
|
The formatter isn't helpful as it currently converts event arrays into strings for writers that work with single strings (e.g. syslog, email). @Maks3w pointed out that the Logger class converts the DateTime object to a string (using the date format option), so we only have a date string to work with in the writer. I opened a thread on the mailing list to propose using formatters for date formatting. In that case, DB writers would still not need a formatter, and they could insert a native date type (better for storage and querying). |
|
@jmikola As noted on the ML, your proposal makes sense. Go ahead and submit that as part of this PR. |
|
@weierophinney on the ML contributor? I have not seen this topic. |
|
@Maks3w thanks :) |
|
@jmikola (short story of actual code) I used to generate the DateTime timestamp, because I prefer it to the date function. And, an event should be a simple type as a string to be able to write easly on anywhere (stderr, file, etc). In Java, everything is an object: the event, a priority for the event, etc. It was not my initial intention of low complexity with all object. But, it can make sense here :) |
|
@b-durand: Yup, I'm subscribed to both lists now, and will be sure to use contributors next time. If this PR is all right, you can merge it whenever you like. I'd prefer to submit another PR with my proposed formatter changes (which will include Logger and writer class changes) and we can work through it using PR comments. I think that'd be more productive than attempting to do it in a gist, as I'm going to implement it in tandem with test alterations. |
This is my first PR, so feel free to scrutinize this thoroughly.
While implementing this, I had a question about the
$eventarguments for thewrite()method. Are all of the values either scalars or an array of scalars? I'm assuming that based on the DB writer'smapEventIntoColumn()andeventIntoColumn()methods, as array values are handled specially (but only one level in). This obviously isn't a problem for Mongo, although I was curious if objects or other types might end up in$eventand could benefit from special processing (e.g. converting DateTime instances to MongoDates).