raylib-rs icon indicating copy to clipboard operation
raylib-rs copied to clipboard

Add initialization option for replacing the internal logger with the Rust `log` crate

Open ewpratten opened this issue 2 years ago • 8 comments

This fixes #94, and supersedes #95

There is no need to link extra C code for replacing the internal logger when Rust is FFI-compatible in both directions.

This PR adds a new function (RaylibBuilder::replace_logger()) that, when called, will redirect all raylib log messages through calls to the log crate. In my particular use case, I am using this to further pass through Tokio's tracing crate, but it can be really used for anything.

Limitations

For now, I have artificially limited this (with a cfg macro) to only happen on Linux (it will just silently not replace the logger on other platforms) due to MSVC throwing a fit about __va_list_tag not existing (presumably since stdarg.h doesn't seem to be standard across compilers). I don't currently have the time to debug this on windows, and don't have the resources to compile it on macos.


This is the first of a small handful of PRs you will see from me, since it is the weekend of Ludum Dare 49, and my team is once again building our entry with this crate.

It also happens to be the month of hacktoberfest. I would appreciate if you could tag this PR as hacktoberfest-accepted weather or not it gets merged so it can count towards my total. More info on hacktoberfest can be found here.

ewpratten avatar Oct 01 '21 14:10 ewpratten

Going to have to look at this one more closely

Dacode45 avatar Oct 07 '21 00:10 Dacode45

Hi, if you're still interested in working on this, some users of the library are moving over to a fork of it which aims to be actively maintained. It would be nice if you reopened the PR there!

IoIxD avatar Jan 31 '24 18:01 IoIxD

I actually looked into this myself, this seems like an extremely promising feature. But I think we should instead make a safe binding to SetTraceLogCallback so that users can use their own logging crate if they want. Do you mind if I do this on the new repo?

IoIxD avatar Jan 31 '24 18:01 IoIxD

Hi @IoIxD I've been maintaining my own similar (with very different goals) rust library for a while now.

https://github.com/ewpratten/raylib-ffi

Optional logging hooks is next on my personal feature list for it actually.

Feel free to make use of my code in this PR for the new fork of this repo if you'd like. I don't mind at all.

If you have further questions or comments or anything, feel free to reach out to me. I don't really keep an eye on the comment notifications for this repo, its actually a coincidence that I happened to glance at my screen when this GitHub notification came through :laughing:

ewpratten avatar Jan 31 '24 18:01 ewpratten

Thanks!

IoIxD avatar Jan 31 '24 18:01 IoIxD

@IoIxD if you do make use of my work, I'd appreciate you @ mentioning me in the commit / PR, just so I can see what you end up doing with it. I'm curious :slightly_smiling_face:

ewpratten avatar Jan 31 '24 18:01 ewpratten

I'm probably gonna redo the commit, actually, to make a safe/public binding to the original function so that other users can use their own custom logger. I'll mention this in the PR though.

IoIxD avatar Jan 31 '24 18:01 IoIxD

ya, of course! Thanks

ewpratten avatar Jan 31 '24 18:01 ewpratten