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

Not every logs are triggering the callback given to "log_set" #268

Closed
azsde opened this issue Dec 20, 2023 · 1 comment
Closed

Not every logs are triggering the callback given to "log_set" #268

azsde opened this issue Dec 20, 2023 · 1 comment

Comments

@azsde
Copy link

azsde commented Dec 20, 2023

Hello,

I am using the python-vlc module on a Raspberry Pi Zero, and I need to be able to detect some events by parsing the logs.

I have successfully redirected the log output to my callback with the following code:

# VLC Logs Callback
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c'))
vsnprintf = libc.vsnprintf

vsnprintf.restype = ctypes.c_int
vsnprintf.argtypes = (
    ctypes.c_char_p,
    ctypes.c_size_t,
    ctypes.c_char_p,
    ctypes.c_void_p,
)

@vlc.CallbackDecorators.LogCb
def log_callback(data, level, ctx, fmt, args):

    # Format given fmt/args pair
    BUF_LEN = 1024
    outBuf = ctypes.create_string_buffer(BUF_LEN)
    vsnprintf(outBuf, BUF_LEN, fmt, args)

    # Print it out, or do something else
    print('MY LOGGER: ' + outBuf.raw.replace(b"\x00",b"").decode())

vlc_instance = vlc.Instance("--no-xlib")
vlc_instance.log_set(log_callback, None)

But some logs are not "sent" to this callback but directly printed in the console.

For instance:

python myScript.py
...
MY LOGGER: deinterlace -1, mode auto, is_needed 0
MY LOGGER: looking for vout window module matching "any": 6 candidates
error: XDG_RUNTIME_DIR not set in the environment.
error: XDG_RUNTIME_DIR not set in the environment.
MY LOGGER: no vout window modules matched
MY LOGGER: Opening vout display wrapper
...

Is there a way to catch those error messages straight from the python script ?

I thank you in advance for your help.

Regards,

Azsde.

@oaubert
Copy link
Owner

oaubert commented Dec 20, 2023

These messages are not native from libvlc, they come from other libraries, hence are not included in the libvlc log system. I would guess that redirecting sys.stderr to a StringIO before instanciating libvlc should allow you to catch these.

@oaubert oaubert closed this as completed Dec 20, 2023
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

No branches or pull requests

2 participants