collective / collective.fingerpointing

Keep track of different events and write them down to an audit log.
https://pypi.org/project/collective.fingerpointing/
5 stars 5 forks source link

Possible unicode issue due to usage of repr #59

Open keul opened 7 years ago

keul commented 7 years ago

I think there's a possible issue if the object logged by fingerpointing is providing a non ASCII __repr__ implementation.

Not sure if this source is right, but (on python 2.7) __repr__ should return a 8-bit string: See https://stackoverflow.com/questions/3627793/best-output-type-and-encoding-practices-for-repr-functions

But lifecycle_logger needs it to be unicode: https://github.com/collective/collective.fingerpointing/blob/8efbe027bbc52ee960a4224c9fa1afc701e9398b/src/collective/fingerpointing/subscribers/lifecycle_logger.py#L31

So: if my __repr__ returns a UTF-8 encoded string with non ASCII chars I have an UnicodeError.

I think that you should convert the repr output to unicode before using it in string interpolation.

hvelarde commented 7 years ago

I'm not sure but I think logger methods are expecting str() instead of unicode(): https://docs.python.org/2/library/logging.html#logrecord-objects

I'm fine with fixing that all over the place.

hvelarde commented 7 years ago

there good information in this @reinout post: http://reinout.vanrees.org/weblog/2015/06/05/logging-formatting.html

also, @domenkozar pointed out this interesting structured logging module: http://structlog.readthedocs.io/