-
-
Save shanewfx/2005632 to your computer and use it in GitHub Desktop.
simple log tool for debug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//===================================================== | |
//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