I am using libwebsockets library. This exposes certain methods for writing into a log file.
lwsl_warn(...)
, lwsl_err(...)
and lwsl_err(...)
to name the most common.
The output is color coded using ANSI sequences.
Is there a way to set the default color scheme (other than recompiling the library)? Thanks.
I poked around in the libwebsockets source and found my answer: The colors are hard coded - so the answer to my original question is "no".
However, the color scheme is not hard to find and edit. It resides in two source files - one of these is compiled depending on options:
libwebsockets/lib/core/logs.c
and
libwebsockets/lib/plat/optee/lws-plat-optee.c
All it takes is to edit the self-explanatory table:
static const char * const colours[] = {
"[31;1m", /* LLL_ERR */
"[36;1m", /* LLL_WARN */
"[35;1m", /* LLL_NOTICE */
"[32;1m", /* LLL_INFO */
"[34;1m", /* LLL_DEBUG */
"[33;1m", /* LLL_PARSER */
"[33m", /* LLL_HEADER */
"[33m", /* LLL_EXT */
"[33m", /* LLL_CLIENT */
"[33;1m", /* LLL_LATENCY */
"[0;1m", /* LLL_USER */
"[31m", /* LLL_THREAD */
};
Then build as before. Once in the libwebsockets/build
directory do the following:
make clean
make && sudo make install
sudo ldconfig
... and enjoy!