title: Losing messages when multiprocess logging with easylogging++ in C++
body: <p>I'm using <a href="https://github.com/amrayn/easyloggingpp" rel="nofollow noreferrer">easylogging++</a> in my app to log messages for control and I've noticed that in production env (which runs under Linux) some messages were disappearing or missing from the log files. I managed to simulate this problem with a simple example in the test environment (on Windows). I made an infinite thread that just keeps on logging a counter and then I executed two instances of my program, here is a resumed example of my code:</p>
  <pre><code>#include &quot;Log/Log.h&quot;
  #include &lt;chrono&gt;
  #include &lt;thread&gt;
  
  INITIALIZE_EASYLOGGINGPP
  
  void log_test() {
      long int count = 0;
      while (true) {
          log_info(&quot;Logando...&quot; + std::to_string(count)); // this is defined in Log.h
          boost::this_thread::sleep(boost::posix_time::milliseconds(10));
          count++;
      }
  }
  
  int main(){
          std::thread t(log_test);
  
          t.detach();
          // rest of the code
  }
  </code></pre>
  <p>and Log.h/Log.cpp are:</p>
  <pre><code>#pragma once
  
  #include &quot;easylogging++.h&quot;
  #include &lt;mutex&gt;
  
  static std::mutex mtx;
  
  void log_info(std::string s);
  void log_error(std::string s);
  </code></pre>
  <p>Log.cpp:</p>
  <pre><code>#include &quot;Log.h&quot;
  
  void log_info(std::string s)
  {
    mtx.lock();
    LOG(INFO, ELPP_THREAD_SAFE) &lt;&lt; s;
    mtx.unlock();
  }
  
  void log_error(std::string s)
  {
    mtx.lock();
    LOG(ERROR, ELPP_THREAD_SAFE) &lt;&lt; s;
    mtx.unlock();
  }
  </code></pre>
  <p>and the both executable files are using the same .conf file with the following configurations:</p>
  <pre><code>* GLOBAL:
     FORMAT               =  &quot;%datetime %msg&quot;
     FILENAME             =  &quot;C:/logs/%datetime{%Y-%M-%d}/msgs.log&quot;
     ENABLED              =  true
     TO_FILE              =  true
     TO_STANDARD_OUTPUT   =  false
     SUBSECOND_PRECISION  =  6
     PERFORMANCE_TRACKING =  true
     MAX_LOG_FILE_SIZE    =  2097152 ## 2MB - Comment starts with two hashes (##)
  </code></pre>
  <p>in the msgs.log file I've noticed this sample:</p>
  <pre><code>2022-06-22 18:51:24,886631 Logando...288
  2022-06-22 18:51:24,901856 Logando...289
  2022-06-22 18:51:24,917820 Logando...5
  
  2022-06-22 18:51:24,932827 Logando...291
  2022-06-22 18:51:24,948248 Logando...292
  </code></pre>
  <p>Where the log 290 is missing from the first process and there's just this blank line instead. I <strong>guess</strong> that one solution could be just using different log files for each process, however it doesn't happen in one single process with multiple threads (instantiating thread t1, t2,t3 as in the code example before). I can't just change one log file to each process in production at the moment since it will have a high impact, so how can I solve it to I don't lose any message at all? Thanks in advance!</p>