Advertisement
es3n1n

logger

May 18th, 2022
880
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define LOG_PREFIX "meme.dll >>"
  2.  
  3.  
  4. static std::mutex log_mutex;
  5. static void log_data( bool should_log_to_file, const char* fmt, ... ) noexcept {
  6.     [[maybe_unused]] std::lock_guard<std::mutex> log_lock( log_mutex );  // @note: @es3n1n: thanks msvc for the warnings
  7.  
  8.     char tmp_buf[ 1024 ];
  9.     va_list va;
  10.     va_start( va, fmt );
  11.     _vsnprintf_s( tmp_buf, 1024, fmt, va );
  12.     va_end( va );
  13.  
  14.     char buf[ 1024 ];
  15.     sprintf_s( buf, sizeof( buf ), "%s %s", LOG_PREFIX, tmp_buf );
  16.  
  17.     //std::printf( "%s\n", buf );
  18.  
  19.     if ( !should_log_to_file )
  20.         return;
  21.  
  22.     std::ofstream out_stream( GLOBAL_LOG_FILE, std::ios::out | std::ios::app );
  23.     out_stream << buf << std::endl;
  24.     out_stream.flush( );
  25.     out_stream.close( );
  26. };
  27.  
  28.  
  29. #define I( fmt, ... ) log_data( true, fmt, __VA_ARGS__ );
  30.  
Advertisement
RAW Paste Data Copied
Advertisement