title: How to enable debug logging with Libwebsockets?
body: <p>I'm trying to implement a websocket client (with libwebsockets in C). I'm using cmake to control the software compilation process. </p>
  
  <p>My question is simple : <strong>How to enable debug logging with Libwebsockets ?</strong></p>
  
  <p>First i compiled and installed libwebsockets like it said in the documentation <em>Notes about building lws</em> :</p>
  
  <blockquote>
    <p>To build with debug info and _DEBUG for lower priority debug messages
    compiled in, use</p>
    
    <p>$ cmake .. -DCMAKE_BUILD_TYPE=DEBUG</p>
  </blockquote>
  
  <p>From <strong>Libwebsockets 2.1</strong> doc <em>Notes about coding with lws</em> 
  (<a href="https://libwebsockets.org/lws-api-doc-master/html/md_README.coding.html" rel="nofollow noreferrer">https://libwebsockets.org/lws-api-doc-master/html/md_README.coding.html</a>) :</p>
  
  <blockquote>
    <p>Debug Logging</p>
    
    <p>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.</p>
    
    <p>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.</p>
    
    <p>The logging apis are made available for user code.</p>
    
    <p>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.</p>
    
    <p>If you are not building with _DEBUG defined, ie, without this</p>
    
    <p>$ cmake .. -DCMAKE_BUILD_TYPE=DEBUG then log levels below notice do
    not actually get compiled in.</p>
  </blockquote>
  
  <p>Like in <a href="https://github.com/warmcat/libwebsockets/blob/v2.1-stable/test-server/test-client.c" rel="nofollow noreferrer">this (official) example</a>, i put <code>lws_set_log_level(10, NULL);</code> at the beginning of my websocket main function. </p>
  
  <p>CMakeLists.txt : </p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Then i run cmake :</p>
  
  <pre><code>cmake .. -DCMAKE_BUILD_TYPE=DEBUG
  make
  </code></pre>
  
  <p>Everything works fine, my websocket client seems ok.</p>
  
  <p>But i've no debug logs... What am i missing ?</p>