로그 메세지 편하게 남기기.
글쓴이: 서지훈 / 작성시간: 목, 2007/09/06 - 1:55오후
예전에 비슷한 주제의 글타래가 있었는데,
최근에 여러 플랫폼에 적용 가능한 걸로 작업 한게 있어 올립니다.
/******************************************************************************* * * File Name : log.c * Decription : 로그 메세지 편하게 출력을... * Version : 1.0 * Date : Tue Oct 2 18:23:03 KST 2007 * Author : Ji Hun, SEO * Email : white23 at gmail.com white23 at suresofttech.com * TODO : fflush()를 선택 할 수 있도록 수정. * ******************************************************************************/ /* checked compiler: - gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) - gcc version 3.3.2: Thread model: aix (AIX 1 5 00572BED4C00) - gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125) - Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 - c89(HP-UX B.11.11 U 9000/800 136911531) - cc(SunOS 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Blade-1000) */ #include <stdio.h> #define __DEBUG__ #if !defined(__FILE__) # define __FILE__ "__FILE__" #endif /* !__FILE__ */ #if !defined(__FUNCTION__) # define __FUNCTION__ "__FUNCTION__" #endif /* !__FUNCTION__ */ #if !defined(__LINE__) # define __LINE__ "__LINE__" #endif /* !__LINE__ */ #if defined(__func__) # define __FUNCTION__ __func__ #endif /* __func__ */ #if defined(_MSC_VER) /* check CL compiler */ # define __LOG_VA_ARGS__ __VAR_ARGS__ #else # if defined(VAR_ARG) # define __LOG_VA_ARGS__ VAR_ARG # else # define __LOG_VA_ARGS__ ... # endif /* VAR_ARG */ #endif #if defined(__DEBUG__) # define LOG_FORMAT1 " ## [%s:%s():%d]: " # define LOG_FORMAT2 __FILE__, __FUNCTION__, __LINE__ # define LOG_PRINT(FMT, __LOG_VA_ARGS__) printf(LOG_FORMAT1 FMT, LOG_FORMAT2, __LOG_VA_ARGS__); fflush(stdout) # define LOG_PRINT_F(FMT) printf(LOG_FORMAT1 FMT, LOG_FORMAT2); fflush(stdout) #else # define LOG_PRINT(__LOG_VA_ARGS__) while (0) # define LOG_PRINT_F(__LOG_VA_ARGS__) while (0) #endif int main(int argc, char *argv[]) { int i = 0, j = 1; LOG_PRINT( "LOG_PRINT format: %s%d, %s%d\n", "i = ", i, "j = ", j ); LOG_PRINT_F( "LOG_PRINT_F format: const string....\n" ); return 0; } /* vi: ts=4: sw=4: */
File attachments:
첨부 | 파일 크기 |
---|---|
log.c.txt | 2.06 KB |
Forums: