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

📄 logfile.cpp

📁 c++的一些源代码
💻 CPP
字号:
//****************************************************
//////////////////////////////////////////////////////
// logfile.cpp
//
//  Change the definition of LOGFILE below or/or move
//  it to your stdafx header file.
//
//////////////////////////////////////////////////////
#define LOGFILE     "C:/Logs/MyApp.log"

void LogMessage (char *fmt, ...)
{
CString     msg, LogFile;
va_list     ap;
CTime       Today = CTime::GetCurrentTime();

    va_start (ap, fmt);
    msg.FormatV (fmt, ap);
    va_end (ap);
    msg += "\r\n";
    LogFile = LOGFILE;
    LogMessage (LogFile, msg);
}

void LogMessage (CString & str)
{
CString     LogFile;
 
    if (g_conf.LogPath.IsEmpty())
        return;
    str += "\r\n";
    LogFile = LOGFILE;
    LogMessage (LogFile, str);
}

//
//  This is the only LogMessage function that will actually
//  write to a log file. All others should boil down to
//  this calling sequence.
//
void LogMessage (CString & fn, CString & msg)
{
FILE        *fp;
CTime       Now = CTime::GetCurrentTime();

    fp = fopen ((LPCSTR) fn, "ab+");
    if (fp != NULL)
    {
        fprintf (fp, "%02d/%02d/%04d %02d:%02d:%02d ",
            Now.GetMonth(), Now.GetDay(), Now.GetYear(),
            Now.GetHour(), Now.GetMinute, Now.GetSecond());
        fprintf (fp, (LPCSTR) msg);
        fclose (fp);
    }
}

//
//  Load a string from the string table using the passed ID,
//  then format a string if necessary.
//
void LogMessage (UINT nID, ...)
{
CString Message;
char    str[512], *pszMessage;
va_list ap;

    if (!Message.LoadString (nID))
        return;
    pszMessage = new char [Message.GetLength() + 1];
    if (pszMessage == NULL)
        return;
    strcpy (pszMessage, (LPCSTR) Message);
    va_start (ap, pszMessage);
    vsprintf (str, pszMessage, ap);
    va_end (ap);
    delete pszMessage;
    Message = str;
    LogMessage (Message);
}

⌨️ 快捷键说明

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