Skip to content

Instantly share code, notes, and snippets.

@RDCH106
Created January 23, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RDCH106/cbfb7c36cdd509d9b370d39f13edf4ac to your computer and use it in GitHub Desktop.
Save RDCH106/cbfb7c36cdd509d9b370d39f13edf4ac to your computer and use it in GitHub Desktop.
C++ logger with logging levels (standard output)
#pragma once
#if defined(___LOG_DEBUG)
# include <iostream>
# define LOGD(...) std::cout << " " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
# define LOGI(...) std::cout << " " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
# define LOGW(...) std::cout << " * Warning: " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
# define LOGE(...) std::cout << " *** Error: " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
#elif defined(___LOG_INFO)
# include <iostream>
# define LOGD(...)
# define LOGI(...) std::cout << " " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
# define LOGW(...) std::cout << " * Warning: " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
# define LOGE(...) std::cout << " *** Error: " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
#elif defined(___LOG_WARNING)
# include <iostream>
# define LOGD(...)
# define LOGI(...)
# define LOGW(...) std::cout << " * Warning: " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
# define LOGE(...) std::cout << " *** Error: " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
#elif defined(___LOG_ERROR)
# include <iostream>
# define LOGD(...)
# define LOGI(...)
# define LOGW(...)
# define LOGE(...) std::cout << " *** Error: " << __VA_ARGS__ << "\t - " << LOG_TAG << std::endl;
#else
// NO LOGS
# define LOGV(...)
# define LOGD(...)
# define LOGI(...)
# define LOGW(...)
# define LOGE(...)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment