'디버그 매크로'에 해당되는 글 1건

  1. 2016.04.19 디버깅 매크로

디버깅 매크로

QT 2016. 4. 19. 15:42

[파일 명][함수:라인] 내용


이런 형식이 필요하여 만들었음.


2018.12.27 수정, 이전 버전은 UTF8 지원이 불가함 (한글 출력 안됨)

수정 버전 사용할 것을 추천..


#ifndef DEFINE_MACRO_H

#define DEFINE_MACRO_H


#include <QDebug>


#define ENTIRE_DEBUG_ON     1

#define DEBUG_VERBOSE       1


#if ENTIRE_DEBUG_ON

#if DEBUG_VERBOSE

#define VERBOSE() qDebug("[%s][%s:%d]", __FILE__, __func__, __LINE__)

#endif

#define DEBUG(MESSAGE) qDebug("[%s][%s:%d] %s", __FILE__, __func__, __LINE__, (MESSAGE))

#define SDEBUG(...) { \

    QString arg; \

    arg.sprintf(__VA_ARGS__); \

    qDebug() << QString("[%1][%2:%3]").arg(__FILE__).arg(__func__).arg(__LINE__) << arg.toUtf8(); \

}

#else

#define VERBOSE() ;

#define DEBUG(MESSAGE) ;

#define SDEBUG(...) ;

#endif


#endif // DEFINE_MACRO_H


ex)

VERBOSE(); // 현재 위치 로그 출력

DEBUG("Something is wrong here"); // 현재 위치에 문자열과 함께 로그 출력

SDEBUG("Something is wrong with value [%d]", wrongValue); // 현채 위치에 printf 포맷 형태로 로그 출력


보면 알겠지만 ENTIRE_DEBUG_ON 을 0으로 바꾸면 모든 디버그 메시지 출력을 끈다.

DEBUG_VERBOSE 를 0으로 바꾸면 VERBOSE만 끈다. 이건 응용해서 디버그 레벨을 조절하면 될듯.



Posted by 독뽀
,