Skip to content

Instantly share code, notes, and snippets.

@zodiac1111
Last active August 29, 2015 14:05
Show Gist options
  • Save zodiac1111/640dee032321739a2722 to your computer and use it in GitHub Desktop.
Save zodiac1111/640dee032321739a2722 to your computer and use it in GitHub Desktop.
打印日志到终端,颜色,线程号等信息
// clog.h
#define DC_LOG_FD stderr ///<日志输出文件描述符,简单的输出到标准错误输出
#define CL_RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define PURPLE "\033[35m"
#define CL_ATTR_REV "\033[7m"
#define CL_ATTR_UNDERLINE "\033[4m"
#define _COLOR "\033[0m"
#define CLOG_TIME clog_time()
#define CLOG_PREFIX "%s==%ld== "
#define CLOG_DEBUG(fmt, ...) \
fprintf(DC_LOG_FD,"D"CLOG_PREFIX PURPLE"%s (%s:%d):%s[%d] "_COLOR fmt "\r\n",\
clog_time(),syscall(SYS_gettid),__FUNCTION__,__FILE__, __LINE__ , \
strerror(errno) ,errno,##__VA_ARGS__ )
// clog.c
char * clog_time(void)
{
time_t t;
struct tm tm;
t = time(NULL);
localtime_r(&t, &tm);
strftime(clog_str_time, 32, "[%F %T]", &tm);
return clog_str_time;
}
// main.c
CLOG_DEBUG();
CLOG_DEBUG("say :%s :%d","hello",n);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment