wa_logger.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #ifndef _WA_LOGGER_HEADER
  3. #define _WA_LOGGER_HEADER
  4. #include <iostream>
  5. #include "spdlog/spdlog.h"
  6. #include "spdlog/async.h" //support for async logging.
  7. #include "spdlog/sinks/basic_file_sink.h"
  8. #include "WAT.h"
  9. #include "..\Winamp\buildType.h"
  10. std::shared_ptr<spdlog::logger> init_log()
  11. {
  12. std::string l_app_version( STR_WINAMP_FILEVER );
  13. wa::strings::replaceAll( l_app_version, ",", "." );
  14. std::string l_app_data_folder( getenv( "APPDATA" ) );
  15. l_app_data_folder.append( "\\Winamp\\winamp.log" );
  16. auto my_wa_logger = spdlog::basic_logger_mt( l_app_version.c_str(), l_app_data_folder.c_str());
  17. spdlog::set_default_logger( my_wa_logger );
  18. spdlog::set_level( spdlog::level::trace );
  19. return my_wa_logger;
  20. }
  21. static std::shared_ptr<spdlog::logger> wa_logger = init_log();
  22. #ifdef _DEBUG
  23. #define LOG_DEBUG(text) spdlog::debug( wa::strings::convert::to_string( text ) );
  24. #define LOG_INFO(text) spdlog::info( wa::strings::convert::to_string( text ) );
  25. #define LOG_WARN(text) spdlog::warn( wa::strings::convert::to_string( text ) );
  26. #define LOG_ERROR(text) spdlog::error( wa::strings::convert::to_string( text ) );
  27. #define LOG_CRITICAL(text) spdlog::critical( wa::strings::convert::to_string( text ) );
  28. #else
  29. #define LOG_DEBUG(text) /* nop */
  30. #define LOG_INFO(text) /* nop */
  31. #define LOG_WARN(text) /* nop */
  32. #define LOG_ERROR(text) spdlog::error( wa::strings::convert::to_string( text ) );
  33. #define LOG_CRITICAL(text) spdlog::critical( wa::strings::convert::to_string( text ) );
  34. #endif // _DEBUG
  35. wchar_t _log_message_w[ DEFAULT_STR_BUFFER_SIZE ];
  36. char _log_message_a[ DEFAULT_STR_BUFFER_SIZE ];
  37. std::string _log_message;
  38. #endif // !_WA_LOGGER_HEADER