taoensso / timbre

Pure Clojure/Script logging library
https://www.taoensso.com/timbre
Eclipse Public License 1.0
1.44k stars 171 forks source link

how to log python dict #351

Closed vinurs closed 2 years ago

vinurs commented 2 years ago

hello, i want to use timbre to log python object with libpython-clj, but it can not log https://github.com/clj-python/libpython-clj/issues/205

ptaoussanis commented 2 years ago

Hi @vinurs,

I'm not familiar with libpython but from your linked issue it looks like the Python type you're trying to log doesn't implement hashing.

As an optimization, Timbre uses internal caching that depends on its arguments being hashed.

What are your appenders doing with the Python object? If you're just printing them (or otherwise coercing them to strings) - one trivial workaround would be to just call str on such Python types when logging.

Timbre intentionally avoids auto-coercing its arguments to strings, since auto-coercing would prevent appenders and middleware from handling raw arguments which can be really handy.

vinurs commented 2 years ago

@ptaoussanis this is my appender

(timbre/merge-config!
   {:timestamp-opts {:pattern "yyyy-MM-dd HH:mm:ss zz",
                     :locale :jvm-default
                     :timezone :jvm-default}
    :appenders {:spit (rolling/rolling-appender
                       {:path    "log/trace-rolling.log"
                        :pattern :daily})}})

thanks for ur suggestion, i just want to log the python object for debug to see its content, so with str is a good idea

ptaoussanis commented 2 years ago

thanks for ur suggestion, i just want to log the python object for debug to see its content, so with str is a good idea

Great, that should work well then 👍