Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance: add a set_logger method #273

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

garfvl
Copy link
Contributor

@garfvl garfvl commented May 3, 2024

This MR adds a way to link libVLC log system to a python logging.Logger object.

A new set_logger method is added to the Instance class to link a logging.Logger to the libvlc_log_set callback setup.
The additional info from the log context (vlc module name, file, line, etc) are attached as extra info.
The log context test is modified to check the set_logger behavior (as the context info is included in the logger).

Tested on Linux and Windows, should work on macOS.

Citing from Python 3.12 release:
"A backslash-character pair that is not a valid escape sequence now generates
 a SyntaxWarning (...) In a future Python version, SyntaxError will eventually
 be raised, instead of SyntaxWarning."

 https://docs.python.org/dev/whatsnew/3.12.html#other-language-changes
Copy link
Owner

@oaubert oaubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Please see if you can address the comments.

generator/templates/override.py Outdated Show resolved Hide resolved
generator/templates/header.py Show resolved Hide resolved
generator/templates/override.py Outdated Show resolved Hide resolved
garfvl added 5 commits May 18, 2024 18:11
Add a way to load the local standard C library.
This could be used to load some C standard functions, like *printf ones.

This should work on Linux, Windows and macOS/Darwin environments.
Adds a way to link libVLC log system to a python logging.Logger object.

The logger and log callback is attached to the libVLC Instance object to avoid
the python garbage collector to destroy them too soon.

NOTE: as libVLC log messages are based on a printf + va_list format, we
need to use the standard C `vsnprintf` function with a max fixed size output.
Adds a functional test for the Instance.set_logger method.
This will also test the log_get_context, as this is part of the logger
output.
This can be useful if some logger is set and you want to get access to
it afterwards.
@oaubert
Copy link
Owner

oaubert commented Aug 23, 2024

I did not forget about this one, but I knew I had another (big) one pending for which I should also dedicated some time. Now that #275 is merged, I can merge this one, but it needs some porting to the new code - no real conflict, just moving things around I think. If you have some time to look at it, great. Else, I will do it some day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants