본문 바로가기

개발 이야기/임베디드 개발

(팁) debug log 로그 출력 시 색깔 별로 구분할 수 있는 방법

728x90

 

 

위 사진과 같이,

임베디드 개발 시 디바이스 디버그 로그를 출력해서 볼 때

칼라를 색깔을 지정하여 보면 가독성이 좋아 집니다.

 

하기와 같이,

debug용 printf에 ANSI코드를 적용해서 하면 됩니다.

 

#define ASCII_COLOR_RED         "\033[1;31m"
#define ASCII_COLOR_WHITE      "\033[1;37m"
#define ASCII_COLOR_YELLOW      "\033[1;33m"
#define ASCII_COLOR_BLUE      "\033[1;36m"
#define ASCII_COLOR_GREEN      "\033[1;32m"
#define ASCII_COLOR_END         "\033[0m"

#define INFORF(fmt, args...)   ({do{fprintf(stderr,ASCII_COLOR_GREEN);fprintf(stderr,fmt,##args);fprintf(stderr,ASCII_COLOR_END);}while(0);})
#define DEBUGF(fmt, args...)   ({do{fprintf(stderr,ASCII_COLOR_YELLOW"[%s:%d]: ",__func__,__LINE__);fprintf(stderr,fmt,##args);fprintf(stderr,ASCII_COLOR_END);}while(0);})
#define ERRORF(fmt, args...)   ({do{fprintf(stderr,ASCII_COLOR_RED"[%s:%s:%d]: ",__FILE__,__func__,__LINE__);fprintf(stderr,fmt,##args);fprintf(stderr,ASCII_COLOR_END);}while(0);})

 

 

그럼,

    공유합니다.