⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coollog.h

📁 一种基于启发式算法(互信息熵)的粗糙集约简源代码
💻 H
字号:
/*
 *  自动设置log文件名,默认位置为exe文件位置下的log文件中
 *  默认的log文件名为exe文件名.log
 *  如果要设置文件名,只要用SETLOGFILEPATH("文件全路径")即可
 *  加入日志用PRINTF("内容%d", 1);即可
*/

#ifndef ______COOLLOG_H______
#define ______COOLLOG_H______

//#define USE_STL
#undef  USE_STL

//#define USE_MFC
#undef  USE_MFC

#ifdef USE_STL
#include <string>
using namespace std;
#endif

/*
 *	Macro definitions
 */
#define IFDEBUG( doit )	doit

#define PRINTF			debug.printf
#define SETLOGFILEPATH  debug.SetLogFileName
#define SHOW_CONSOLE	debug.ShowConsole();
#define HIDE_CONSOLE	debug.HideConsole();
#define SHOW_LASTERROR	debug.ShowLastError();
#define CLOSE_LOG		debug.CloseLog();

/*-----------------------------------------------------------------------
 *  Class        : CDebugPrintf
 *  Prototype    : class CDebugPrintf
 *  Description  : 
 *  Parent class : 
 *  History      : 
 */
class CDebugPrintf
{
public:
	CDebugPrintf();
	virtual ~CDebugPrintf();

	void printf( const char *fmt, ... );

#ifdef USE_STL
	void printf( string& str ) { printf( str.c_str() ); }
	void printf( string* str ) { printf( str->c_str() ); }
#endif

#ifdef USE_MFC
	void printf( CString& str ) { printf( str.GetBuffer(1024) ); }
	void printf( CString* str ) { printf( str->GetBuffer(1024) ); }
#endif

	void CloseLog();

	void ShowConsole(); 
	void HideConsole(); 
	void ShowLastError();
	bool SetLogFileName(const char *szFilePath);

private:
	bool Init();
	HANDLE			 m_hFile;					// log-file handle
	HANDLE			 m_hDebugMutex;				// allow to check that log-file is open by other process 
	CRITICAL_SECTION m_hLock;					// lock for thread-safe access

	DWORD			 m_dwStartTime;				// application start time 
	bool			 m_bUseConsole;				// use or not log-console with log-file
	bool			 m_bStartLogFlag;			// start log flag

	HANDLE			 m_hConWrite;				// console handle
	TCHAR			 m_szLogFileName[_MAX_PATH];// log file path
	TCHAR			 m_szShowConsolePath[_MAX_PATH];// show console path
};

extern CDebugPrintf debug;

#endif


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -