websocketpp icon indicating copy to clipboard operation
websocketpp copied to clipboard

Improved custom logging

Open Sil3ntStorm opened this issue 2 years ago • 2 comments

It's basically impossible to add custom logging for this, as the logger instance is forcefully created internally within the library for each connection and you don't get to have any access to it, which makes it unnecessarily hard to have uniform logging.

It would be much preferable to have the option to specify the logger, by either passing it to the constructor of the client / server objects, or have callbacks that are called for logging purposes.

Sil3ntStorm avatar Dec 09 '22 22:12 Sil3ntStorm

please check iostream server example https://github.com/zaphoyd/websocketpp/blob/master/examples/iostream_server/iostream_server.cpp you can set your own output stream but consider that "C++ iostream's don't support the idea of asynchronous"

loupus avatar Feb 15 '23 14:02 loupus

I have not looked into those functions (and probably won't have the time to for at least a few weeks), but it sounds like those might be specific to iostreams.

My intention was more along the lines of having the option to log using whatever method I desire and not having to hardcode in any kind of specifics, especially with regards to developing libraries for third party consumption that use this.

However the log backend is hardcoded in the config struct and there is no access (that I had seen) to those from clients which would allow to replace / change their functionality from the outside. It might however be possible to implement some kind of callback system with get_alog() / get_elog() and just having some sort of skeleton logger that does not actually do anything but offer the ability to set callbacks and call them when websocketpp would like to log things. Will have to look into that when I find some time.

Sil3ntStorm avatar Feb 26 '23 01:02 Sil3ntStorm