I'm trying to implement a websocket client (with libwebsockets in C). I'm using cmake to control the software compilation process.
My question is simple : How to enable debug logging with Libwebsockets ?
First i compiled and installed libwebsockets like it said in the documentation Notes about building lws :
To build with debug info and _DEBUG for lower priority debug messages compiled in, use
$ cmake .. -DCMAKE_BUILD_TYPE=DEBUG
From Libwebsockets 2.1 doc Notes about coding with lws (https://libwebsockets.org/lws-api-doc-master/html/md_README.coding.html) :
Debug Logging
Also using lws_set_log_level api you may provide a custom callback to actually emit the log string. By default, this points to an internal emit function that sends to stderr. Setting it to NULL leaves it as it is instead.
A helper function lwsl_emit_syslog() is exported from the library to simplify logging to syslog. You still need to use setlogmask, openlog and closelog in your user code.
The logging apis are made available for user code.
lwsl_err(...) lwsl_warn(...) lwsl_notice(...) lwsl_info(...) lwsl_debug(...) The difference between notice and info is that notice will be logged by default whereas info is ignored by default.
If you are not building with _DEBUG defined, ie, without this
$ cmake .. -DCMAKE_BUILD_TYPE=DEBUG then log levels below notice do not actually get compiled in.
Like in this (official) example, i put lws_set_log_level(10, NULL);
at the beginning of my websocket main function.
CMakeLists.txt :
cmake_minimum_required(VERSION 3.6)
project(foo)
set(CMAKE_C_STANDARD 11)
set(CMAKE_BUILD_TYPE DEBUG) #For CLion IDE but i'm pretty sur it does nothing.
set(SOURCE_FILES
websocket.c
websocket.h
main.c)
add_executable(foo ${SOURCE_FILES})
target_link_libraries(foo websockets)
Then i run cmake :
cmake .. -DCMAKE_BUILD_TYPE=DEBUG
make
Everything works fine, my websocket client seems ok.
But i've no debug logs... What am i missing ?