log4mongo / log4mongo-java

log4j appender to MongoDB database
http://log4mongo.org
Apache License 2.0
80 stars 29 forks source link

Exception when a MDC property key contains a dot #22

Closed undso closed 9 years ago

undso commented 10 years ago

I get an exception in the method: org.log4mongo.LoggingEventBsonifierImpl.addMDCInformation() when the MDC properties has an entry where the key contains a dot.

To fix this issue I see two ways: 1) Ignore properties with such a key. 2) Replace all dots with an other sign (e.g. '_')

Which way should we go? I prefer number 2, because we loose not data, but I know there can be a problem when there is another property which then has the same key.

RobertStewart commented 10 years ago

That's a tough one. Thanks for pointing it out. Do you think it's possible to change the code to properly handle the case where the key has a dot? I can't test it right now, but will take a look tonight.

If not, I'm also inclined to go with option 2.

undso commented 10 years ago

The appender can handle the dot. The problem is the mongodb. There is a restriction field names cannot contain dots (i.e. .), dollar signs (i.e. $), or null characters. http://docs.mongodb.org/manual/reference/limits/#Restrictions on Field Names

I'll implement option 2 and create a pull request.