最近项目出现点小Bug,需要调试跟踪代码,于是乎写了份打印日志的代码。

CLogFile.h文件

 #if !defined(AFX_LOGFILE_H__288388CA_9A3E_4F3D_A2B8_F1078E1F6A6B__INCLUDED_)
#define AFX_LOGFILE_H__288388CA_9A3E_4F3D_A2B8_F1078E1F6A6B__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 class CLogFile
{
public:
CLogFile();
~CLogFile();
private:
static CString GetFileName();
static CString GetFilePath();
public:
static bool WriteLog(CString LogText);
}; #endif // !defined(AFX_LOGFILE_H__288388CA_9A3E_4F3D_A2B8_F1078E1F6A6B__INCLUDED_)

CLogFile.cpp文件

 #include "stdafx.h"
#include "CLogFile.h" CLogFile::CLogFile()
{ } CLogFile::~CLogFile()
{ }
//获取文件名称
CString CLogFile::GetFileName()
{
CString sFileName; sFileName = CTime::GetCurrentTime().Format("%Y-%m-%d") + TEXT(".log"); return sFileName;
} //获取应用程序所在路径
CString CLogFile::GetFilePath()
{
CString m_FilePath; GetModuleFileName(NULL,m_FilePath.GetBufferSetLength(MAX_PATH+),MAX_PATH); m_FilePath.ReleaseBuffer(); int m_iPosIndex; m_iPosIndex = m_FilePath.ReverseFind('\\'); //m_FilePath = m_FilePath.Left(m_iPosIndex) + TEXT("\\Log");
m_FilePath = "D:\\VISTA\\LOGSA"; return m_FilePath;
} bool CLogFile::WriteLog(CString LogText)
{
try
{
//CFile m_File;
CFile m_SFile;
CFileFind m_FileFind;
CString m_sErrorMessage;
CString m_sFileName = GetFileName();
CString m_sFilePath = GetFilePath();
CString m_sCurrentTime = CTime::GetCurrentTime().Format("%Y-%m-%d %X"); if(!m_FileFind.FindFile(m_sFilePath))
{
CreateDirectory(m_sFilePath,NULL);
} m_SFile.Open(m_sFilePath + TEXT("\\") +m_sFileName,CFile::modeCreate |CFile::modeNoTruncate| CFile::modeReadWrite |CFile::shareDenyWrite);
/*{
m_SFile.Open(m_sFilePath + TEXT("\\") + m_sFileName,CFile::modeCreate | CFile::modeReadWrite |CFile::shareDenyWrite| CFile::typeText);
}*/ m_SFile.SeekToEnd(); if(sizeof(TCHAR)==sizeof(WCHAR))
{
WORD wSignature = 0xFEFF;
m_SFile.Write(&wSignature, );
} //TCHAR* m_szMessage; //m_szMessage=m_sErrorMessage.GetBuffer(); m_sErrorMessage = TEXT("*******************") + m_sCurrentTime + TEXT("*******************")+TEXT("\r\n") ;
m_SFile.Write(m_sErrorMessage,m_sErrorMessage.GetLength()*sizeof(TCHAR)); //m_sErrorMessage = LogText ;
LogText+=TEXT("\r\n");
m_SFile.Write(LogText,LogText.GetLength()*sizeof(TCHAR));
//m_sErrorMessage = TEXT("*******************") + m_sCurrentTime + TEXT("*******************") ;
m_SFile.Write(m_sErrorMessage,m_sErrorMessage.GetLength()*sizeof(TCHAR)); //m_SFile.Write(m_sErrorMessage.GetBuffer(),m_sErrorMessage.GetLength()); m_SFile.Close();
}
catch(CFileException fileException)
{
return false;
} return true;
}

以上代码经过调试通过!

MFC下调试日志的打印的更多相关文章

  1. MFC 下调试 出现 warning : fail to load indicator string 0x0069

    MFC 下调试 出现 warning : fail to load indicator string 0x0069 就是程序状态栏每一个标识列中至少有一个值没有初始值 或初始值为空 导致程序没有获取到 ...

  2. MFC下调试 出现 Warning: initial dialog data is out of range.

    在mfc Debug模式下出现"Warning: initial dialog data is out of range."提示..原因是出现在 DDV_MinMaxInt 对应的 ...

  3. NodeJS学习笔记 进阶 (11)Nodejs 进阶:调试日志打印:debug模块

    个人总结:读完这篇文章需要5分钟,讲解了debug模块的使用 摘选自网络 前言 在node程序开发中时,经常需要打印调试日志.用的比较多的是debug模块,比如express框架中就用到了.下文简单举 ...

  4. windows系统下,express构建的node项目中,如何用debug控制调试日志

    debug是一款控制日志输出的库,可以在开发调试环境下打开日志输出,生产环境下关闭日志输出.这样比console.log方便多了,console.log只有注释掉才能不输出. debug库还可以根据d ...

  5. Tomcat - 怎么控制某个类或者包下的日志打印级别

    问题与分析 Tomcat是使用自己的日志实现tomcat-juli.jar来打印日志信息的,日志会被打印到catalina.out里,除去你在项目里自己使用的日志框架外,由System.out,Sys ...

  6. sqlserver下调试sql语句

    现在版本的sqlServer已经支持调试功能了,但是在使用的时候用到的却很少(毕竟print习惯了..) 这里做一个笔记,简单的说明一下在sqlserver下调试的方法: declare @i int ...

  7. 关于调试日志Log

    __VA_ARGS__  是一个可变参数的宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持(VC6.0的编译器不支持).宏前面加上##的作用在于,当可变参数的个数为0时,这里的## ...

  8. Linux下追踪函数调用,打印栈帧

    事情的起因是这样的,之前同事的代码有一个内存池出现了没有回收的情况.也就是是Pop出来的对象没有Push回去,情况很难复现,所以在Pop里的打印日志,跟踪是谁调用了它,我想在GDB调试里可以追踪调用的 ...

  9. Log4j配置详解及不同的包(package)下的日志写入到不同的日志文件下

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt262 以下都是log4j.properties要写入的内容: 一:参数介绍: ...

随机推荐

  1. 3-Dom

    HTML DOM 对象DOM DocumentDOM ElementDOM AttributeDOM Event Document对象 每个载入浏览器的 HTML 文档都会成为 Document 对象 ...

  2. Git之”make sure you have the correct access…”

    git 命令在windows下无法使用pull.fetch.push等命令,提示 “please make sure you have the correct access and the repos ...

  3. Apache php无法开启php_curl

    解决办法: 将php安装目录下的libeay32.dll,libssh2.dll,php5ts.dll,php_curl.dll,ssleay32.dll 复制到system32目录下 在httpd. ...

  4. Elasticsearch .net 客户端条件拼接查询

    private Func<SearchDescriptor<BaseTest>, ISearchRequest> ConstructWhere(TestCondition wh ...

  5. CentOs + Nginx + php-fpm + MySql 依赖库安装

    依赖库和开发工具 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype free ...

  6. win7安装omnetpp-4.6

    最近做毕设要用omnet仿真系统,就试着在win7上装了一下,分享一下经验咯.因为lz经常刷机,所以安装过程都是从头再来的,费话不多说.下面是安装过程: (1)    安装jdk,我就百度一下,然后找 ...

  7. 提取出图像中感兴趣的部分,cvSetImageRoi,Rect

    在做人脸检测的时候,需要从摄像头拍摄视频中把检测到的人脸区域提取出来,网上找了很多博客,发现多数都是在用cvSetImageRoi函数,该函数声明如下:void cvSetImageROI(IplIm ...

  8. linux下获取硬盘、内存、U盘大小及使用大小

    /* * 获取硬盘大小;内存大小;usb大小 */ #ifndef SYSINFOGET_H #define SYSINFOGET_H #include <stdio.h> //磁盘信息 ...

  9. 转:jquery的live和on

    参考1,参考2 给元素绑定事件,本人用的jquery版本大多为1.7和1.8的,所以一直习惯于用live(),但是最近朋友突然问我,怎么给新生成的dom元素绑定事件,我随口回答live(),结果他给我 ...

  10. Python ---------copy

    copy---探索 1.浅copy    就相当于把变量指针指向对象 相当于给对象从新起了个小名 a=[[1,2],3,4] a=[[1,2],3,4] b=a.copy() # print(a) # ...