写日志的函数,直接复制使用
来源:互联网 发布:论文格式 知乎 编辑:程序博客网 时间:2024/05/20 16:13
为了方便调试,直接复制下面函数就可以使用日志打印功能
void PrintDebugLog(CString pValue, CString pEvent=""){
char V[100];
char E[100];
char szFilename[1024];
CString strPath = CINIFile::GetAppPath() +"\\TempDebugLog\\";
CreateDirectory("TempDebugLog",NULL);
SHCreateDirectoryEx(NULL, strPath, NULL);
CTime time = CTime::GetCurrentTime();
wsprintf(szFilename, "%s%d%d%d%d-log.txt",
strPath , time.GetYear(), time.GetMonth(), time.GetDay(),time.GetHour());
FILE *fp = fopen( szFilename, "a" );
if (NULL == fp)
{
return;
}
//插入时间
char cTime[30];
::memset(cTime,0,sizeof(cTime));
sprintf(cTime,"[%d:%d:%d] ",time.GetHour(),time.GetMinute(),time.GetSecond());
fprintf(fp,cTime);
if (pEvent.GetLength() > 0)
{
sprintf(E,"事件:%s;",pEvent);
fprintf(fp, E);
}
sprintf(V,"值:%s",pValue);
va_list arg;
va_start( arg, V );
vfprintf(fp, V, arg );
fprintf(fp,"\n");
fclose(fp);
}
第二种方法可进行参数格式化:
void DebugPrintf(const char *p, ...)
{
char szFilename[256];
CString strPath = CINIFile::GetAppPath() +"\\TempDebugLog\\";
CreateDirectory("TempDebugLog",NULL);
CTime time = CTime::GetCurrentTime();
sprintf(szFilename,"%s%d%d%d_log.txt",strPath ,time.GetYear(), time.GetMonth(), time.GetDay());
FILE *fp = fopen( szFilename, "a" );
if (NULL == fp)
{
return;
}
//插入时间
char cTime[30];
::memset(cTime,0,sizeof(cTime));
sprintf(cTime,"[%d:%d:%d] ",time.GetHour(),time.GetMinute(),time.GetSecond());
fprintf(fp,cTime);
va_list arg;
va_start( arg, p );
vfprintf(fp, p, arg );
fprintf(fp,"\n");
fclose(fp);
}
使用格式:
int i = 0;
DebugPrintf("参数【%d】,参数【%d】,参数【%d】",i,++i,++i);
0 0
- 写日志的函数,直接复制使用
- WinCE5.0下直接写屏 -- 函数 CreateDIBSection() 的使用
- PostgreSQL基于预写日志的复制
- 自己写的日志函数
- 日志文件系统的写日志函数
- Android直接复制使用的工具类
- 图片拉伸通常我们开发中将其写到UIImage的分类中使用,下面可以直接复制使用
- 自己写的字符串复制函数
- 如何写自己的内存复制函数?
- 写一个函数,实现字符串的复制
- WinCE5.0下直接写屏操作与函数 CreateDIBSection() 的使用
- WinCE5.0下直接写屏操作与函数 CreateDIBSection() 的使用
- C#使用StreamWriter写日志,直接在根目录下生成日志文件
- TCHAR型版本的写日志函数
- Qt下写日志文件的函数
- 输入输出函数的应用--写日志
- 写软件运行日志的函数
- 如何使用Fread和Fwrite写一个复制文件的函数
- 修改android theme的问题
- LeetCode-Insertion Sort List
- 量化研究: Julia还是Matlab?
- 关于插入排序
- pdf如何转换成ppt
- 写日志的函数,直接复制使用
- 自己动手写Java大整数《4》扩展欧几里得和Mod逆
- 【Visual C++】游戏开发笔记三十五 站在巨人的肩膀上:游戏引擎导论
- 分布式ActiveMQ集群
- Java中获取进程ID以及杀死进程的方法
- 0-----------假 , 非0----------------真
- 去我空间分会去靠近我会放开去将
- 去我空间分其加快我分不清
- C++编写pingIP的程序