Advertisement
markoczy

Logger WIP

Aug 23rd, 2023
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. // Note: Need to do in FP (-_-)
  9.  
  10. // AM guerrilla logger
  11. std::vector<std::wstring> amLogs;
  12.  
  13. template<typename... TObj>
  14. void amLogFn(std::string aFunction, int aLine, TObj... aArgs) {
  15.    
  16.     std::wstring fn(aFunction.begin(), aFunction.end());
  17.     std::wstringstream ss;
  18.     ss << fn << L"[" << aLine << L"]: ";
  19.     for (const auto obj : {aArgs...}) {
  20.         ss << obj;
  21.     }
  22.     ss << endl;
  23.     amLogs.push_back(ss.str());
  24. }
  25. std::wstring amPrintFn() {
  26.     std::wstringstream ss;
  27.     for(const auto& s : amLogs) {
  28.         ss << s;
  29.     }
  30.     return ss.str();
  31. }
  32. #define AMLOG(...) amLogFn(__FUNCTION__, __LINE__, __VA_ARGS__, L"AMTERM")
  33. #define AMPRINT amPrintFn()
  34.  
  35. int main()
  36. {
  37.     AMLOG(L"Hi ", L"Test");
  38.     AMLOG(L"Hi", L"Test", 213);
  39.     const auto s = AMPRINT;
  40.     std::wcout << s;
  41. }
  42.  
  43. // GCC reference:
  44. //   https://gcc.gnu.org/
  45.  
  46. // C++ language references:
  47. //   https://cppreference.com/
  48. //   https://isocpp.org/
  49. //   http://www.open-std.org/jtc1/sc22/wg21/
  50.  
  51. // Boost libraries references:
  52. //   https://www.boost.org/doc/
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement