thezxtreme

log_class

Nov 16th, 2016
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cinttypes>
  3. #include <random>
  4.  
  5. enum class LogLevel : uint8_t
  6. {
  7.     Information, Debug, Error, Custom
  8. };
  9.  
  10. class Log final
  11. {
  12.     public:
  13.         template <typename ...T> void write(const LogLevel& log_level, const T& ... object) noexcept
  14.         {
  15.             const auto get_log_level = [&]()
  16.             {
  17.                 switch (log_level)
  18.                 {
  19.                     case LogLevel::Information: return "[Information]: ";
  20.                     case LogLevel::Debug: return "[Debug]: ";
  21.                     case LogLevel::Error: return "[Error]: ";
  22.                     case LogLevel::Custom: return "[Custom case]: ";
  23.  
  24.                     default: return "[Unknown log level]: ";
  25.                 }
  26.             };
  27.  
  28.             std::cout << get_log_level();
  29.             (void)std::initializer_list<int>{ (std::cout << object, 0x0)...};
  30.             std::cout << '\n';
  31.         }
  32. };
  33.  
  34. int main()
  35. {
  36.     Log log;
  37.     log.write(LogLevel::Debug, "Hello", " from second ", " argument with data: ", 123, " ", 2.22f);
  38.     log.write(LogLevel::Custom, "Testing results.");
  39.  
  40.     return 1;
  41. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×