dylanbstorey / pyo3-pylogger

log messages for pyo3 embedded Python applications using the logging module
Apache License 2.0
3 stars 2 forks source link

lib: use pathname for record file #7

Closed cpu closed 2 months ago

cpu commented 2 months ago

Previously the RecordBuilder used in host_log() to construct a Log item hardcoded the record's file() as Some("app.rs"). https://github.com/dylanbstorey/pyo3-pylogger/blob/d89e0d6820ebc4f067647e3b74af59dbc4941dd5/src/lib.rs#L72

This branch updates the logic to use &pathname ("Full pathname of the source file where the logging call was issued (if available).") instead.

This value is already being provided to module_path(), but arguably that usage should be changed to record.getattr("module") (described in the python docs as "Module (name portion of filename).") instead of record.getattr("pathname"). I've left that as-is for now pending discussion since it doesn't affect the default formatting of tracing events, and that's where my focus is today.

Before this change when using tracing-log to adapt the Log record to the tracing ecosystem w/ default formatting an event like the following was produced:

2024-07-23T15:31:24.376313Z DEBUG init: app.rs:10: User Python Loaded!

Afterwards, it produces an event like:

2024-07-23T15:50:38.273451Z DEBUG init: /home/daniel/.config/pup/user_test.py:10: User Python Loaded!

Along the way I tidied up the builder construction a little bit :-)

Relates to https://github.com/dylanbstorey/pyo3-pylogger/issues/5

cpu commented 2 months ago

(Note: this will fail in CI until https://github.com/dylanbstorey/pyo3-pylogger/pull/6 is merged - the project's relaxed version requirement for pyo3 means it's pulling in 0.22 but not activating the gil-refs feature to allow using deprecated APIs).

dylanbstorey commented 2 months ago

Very nice - thanks for the thoughful explanation and PR !

dylanbstorey commented 2 months ago

released with 0.3.0

cpu commented 1 month ago

released with 0.3.0

@dylanbstorey it looks like 0.2.2 is the latest release available on crates.io. Can I trouble you to publish 0.3.0 there?

cpu commented 1 month ago

I think the Cargo.toml version needs a bump first too: https://github.com/dylanbstorey/pyo3-pylogger/blob/e69fee5949f220178623fa542cf758cd33c7b8ab/Cargo.toml#L3

Sorry, just coming back around now trying to pick this change up in my dependent project.

dylanbstorey commented 1 month ago

Merged and released correctly this time. Soz!