Skip to content

Instantly share code, notes, and snippets.

@shanewfx
Created March 9, 2012 08:22
Show Gist options
  • Save shanewfx/2005632 to your computer and use it in GitHub Desktop.
Save shanewfx/2005632 to your computer and use it in GitHub Desktop.
simple log tool for debug
//=====================================================
//simple log tool for debug
//=====================================================
#ifndef _LOGTOOL_H_
#define _LOGTOOL_H_
#include <stdio.h>
#include <windows.h>
//#define TEST
#define LOGFILENAME "C:\\DebugLog\\log.txt"
#ifdef TEST
#define LogData(fmt,var) {\
sprintf(g_LogTextBuf,fmt,var);\
fwrite(g_LogTextBuf,strlen(g_LogTextBuf),1,g_pLogFile);\
}
#define LogText(str) {\
sprintf(g_LogTextBuf,str);\
fwrite(g_LogTextBuf,strlen(g_LogTextBuf),1,g_pLogFile);\
}
#define TOpenFile() {\
CreateDirectory("C:\\DebugLog",NULL);\
g_pLogFile=fopen(LOGFILENAME,"w");\
SYSTEMTIME st;\
GetLocalTime(&st);\
sprintf(g_LogTextBuf,"====Open file at %02u:%02u:%02u====\n",st.wHour,st.wMinute,st.wSecond );\
fwrite(g_LogTextBuf,strlen(g_LogTextBuf),1,g_pLogFile);\
}
#define TCloseFile() {\
SYSTEMTIME st;\
GetLocalTime(&st);\
sprintf(g_LogTextBuf,"====Close file at %02u:%02u:%02u====\n",st.wHour,st.wMinute,st.wSecond );\
fwrite(g_LogTextBuf,strlen(g_LogTextBuf),1,g_pLogFile);\
fclose(g_pLogFile);\
}
#define DefineVar()\
FILE* g_pLogFile;\
char g_LogTextBuf[256];\
LONG g_lLogCount1=0;\
LONG g_lLogCount2=0;
#define DeclareVar()\
extern FILE* g_pLogFile;\
extern char g_LogTextBuf[256];\
extern LONG g_lLogCount1;\
extern LONG g_lLogCount2;
#define FlushData() fflush(g_pLogFile)
#define LogTime() {\
SYSTEMTIME st;\
GetLocalTime(&st);\
sprintf(g_LogTextBuf,"[%02u:%02u:%02u:%03u] ",st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);\
fwrite(g_LogTextBuf,strlen(g_LogTextBuf),1,g_pLogFile);\
}
#else
#define LogData(fmt,var)
#define LogText(str)
#define TOpenFile()
#define TCloseFile()
#define DefineVar()
#define DeclareVar()
#define FlushData()
#define LogTime()
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment