ACE_DEBUG, ACE_ERROR, ACE_ERROR_RETURN
이 세가지 매크로는, MFC 의 TRACE 처럼 쓸수 있는 유용한 매크로들이다.우선 소스부터...
#include "ace/OS.h" #include "ace/Log_Msg.h" int cause_error(); int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { ACE_DEBUG((LM_DEBUG, "some debug message %s\n", "like printf")); ACE_ERROR((LM_ERROR, "some error message %p\n", "SomeFunc()")); cause_error(); ACE_ERROR_RETURN((LM_ERROR, "some error message %p and return\n", "cause_error()"), -1); ACE_DEBUG((LM_DEBUG, "program end\n")); return 0; } int cause_error() { errno = 6666; return -1; }
실행하면 다음과 같다.
some debug message like printf some error message cause_error(): Success some error message cause_error(): <unknown error> = 6666 and return
추가적인 format specifier
%1 |
라인 넘버 |
%N |
파일 이름 |
%n |
프로그램 이름 |
%P |
현재 프로세스 ID |
%p |
하나의 const char* 인자(함수이름)를 받아서, 그 스트링뒤에 perror(errno) 의 형태의 값을 출력 |
%T |
현재 시각 |
%t |
thread id |
단, 이중 %n 은 그냥 찍어보니 unknown 이 나오더라. 이값을 세팅해 주려면, ACE_LOG_MSG 의 open() 을 불러줘야 한다. 이 내용은 ace/ACE_LOG_MSG에...
참고로, 위 소스에 다음을 추가하고
ACE_DEBUG((LM_DEBUG, "this program is %n\n")); ACE_DEBUG((LM_DEBUG, "this process ID is %P\n")); ACE_DEBUG((LM_DEBUG, "this process time is %T\n"));
찍은 결과는
this program is <unknown> this process ID is 12841 this process time is 17:06:20.943376
이렇더라. 시각이 초단위 보다 아래쪽(나노인가?) 까지 나오는것에 감동.1
Ace_Log_Priority
위의 LM_어쩌구 는 $(ACE_ROOT)\ace\Log_Priority.h 에서 찾아볼수 있다. 코드를 간단히 정리해 보면,
enum ACE_Log_Priority { // = Note, this first argument *must* start at 1! /// Shutdown the logger (decimal 1). LM_SHUTDOWN = 01, /// Messages indicating function-calling sequence (decimal 2). LM_TRACE = 02, /// Messages that contain information normally of use only when /// debugging a program (decimal 4). LM_DEBUG = 04, /// Informational messages (decimal 8). LM_INFO = 010, /// Conditions that are not error conditions, but that may require /// special handling (decimal 16). LM_NOTICE = 020, /// Warning messages (decimal 32). LM_WARNING = 040, /// Initialize the logger (decimal 64). LM_STARTUP = 0100, /// Error messages (decimal 128). LM_ERROR = 0200, /// Critical conditions, such as hard device errors (decimal 256). LM_CRITICAL = 0400, /// A condition that should be corrected immediately, such as a /// corrupted system database (decimal 512). LM_ALERT = 01000, /// A panic condition. This is normally broadcast to all users /// (decimal 1024). LM_EMERGENCY = 02000, /// The maximum logging priority. LM_MAX = LM_EMERGENCY, /// Do not use!! This enum value ensures that the underlying /// integral type for this enum is at least 32 bits. LM_ENSURE_32_BITS = 0x7FFFFFFF };
과 같다. LM_DEBUG, LM_INFO, LM_ERROR, LM_CRITICAL 네가지 정도만 잘 쓰면 될것 같은데...
- LM_DEBUG : 디버깅을 위해서만 쓰는 log
- LM_INFO : 현재 프로그램의 진행상황, 정보등을 나타내는 log
- LM_ERROR : 에러( 단 복구 가능하거나, 발생이 예측되는 에러들을... )
- LM_CRITICAL : 에러( 처리가 불가능하거나, 도저히 발생을 예측하지 못한 에러들의... )
1 아마 clock_gettime을 쓴모양이지?
