Created
April 4, 2018 07:02
-
-
Save anonymouss/27a2bf343558a5ee1aaabf3df3e35d14 to your computer and use it in GitHub Desktop.
log test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define LOG_LEVEL_VERBOSE 0 | |
#define LOG_LEVEL_DEBUG 1 | |
#define LOG_LEVEL_INFO 2 | |
#define LOG_LEVEL_WARNING 3 | |
#define LOG_LEVEL_ERROR 4 | |
#define DEBUG_LEVEL LOG_LEVEL_INFO | |
#define LOG_TAG "TEST_LOG" | |
#define TRIM_STR(n, str) str[n] | |
#define TS_PRINTF(fmt, x...) \ | |
{ \ | |
auto tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); \ | |
struct tm* ptm = localtime(&tt); \ | |
fprintf(stdout, "%d-%02d-%02d | %02d:%02d:%02d | " fmt "\n", \ | |
(int)ptm->tm_year + 1900,(int)ptm->tm_mon + 1,(int)ptm->tm_mday, \ | |
(int)ptm->tm_hour,(int)ptm->tm_min,(int)ptm->tm_sec, \ | |
##x); \ | |
} | |
#define LOG(level, fmt, x...) \ | |
{ \ | |
if (level >= DEBUG_LEVEL) \ | |
TS_PRINTF("%c: %s : %s: %d | " fmt, TRIM_STR(10, #level), LOG_TAG, __func__, __LINE__, ##x); \ | |
} | |
#define LOGV(fmt, x...) LOG(LOG_LEVEL_VERBOSE, fmt, ##x) | |
#define LOGD(fmt, x...) LOG(LOG_LEVEL_DEBUG, fmt, ##x) | |
#define LOGI(fmt, x...) LOG(LOG_LEVEL_INFO, fmt, ##x) | |
#define LOGW(fmt, x...) LOG(LOG_LEVEL_WARNING, fmt, ##x) | |
#define LOGE(fmt, x...) LOG(LOG_LEVEL_ERROR, fmt, ##x) | |
int main() { | |
LOGV("This is a test log, %s", "verbose"); // < default, won't print | |
LOGD("This is a test log, %s", "debug"); // < default, won't print | |
LOGI("This is a test log, %s", "info"); // = default, print | |
LOGW("This is a test log, %s", "warning"); // > default, print | |
LOGE("This is a test log, %s", "error"); // > default, print | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment