📄 logtofile.c
字号:
#include "LogToFile.h"
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "AEEDB.h" // Database interface definitions
#include "AEENet.h" // Socket interface definitions
#include "AEESound.h" // Sound Interface definitions
#include "AEETapi.h" // TAPI Interface definitions
void LogToFile(const char *pFileName, const int nLine, const char *pLogBuf)
{
IFileMgr *m_pIFileMgrTest;
IFile *m_pIFileTest;
char *pFindFileName = NULL;
char *pBuf = NULL;
char *pBufForLine = NULL;
IShell* pIShell;
pIShell = ((AEEApplet*)GETAPPINSTANCE())->m_pIShell;
pBuf = (char *)malloc(256);
pBufForLine = (char *)malloc(16);
pFindFileName = STRRCHR(pFileName, '\\');
pFindFileName++;
if (NULL == pFindFileName)
{
return;
}
STRCPY(pBuf, pFindFileName);
SPRINTF(pBufForLine, " %d ", nLine);
STRCAT(pBuf, pBufForLine);
STRCAT(pBuf, pLogBuf);
ISHELL_CreateInstance(pIShell, AEECLSID_FILEMGR, (void **)&m_pIFileMgrTest);
if (NULL == m_pIFileMgrTest)
{
return;
}
if (SUCCESS == IFILEMGR_Test(m_pIFileMgrTest, "mylog.log"))
{
m_pIFileTest = IFILEMGR_OpenFile(m_pIFileMgrTest, "mylog.log", _OFM_APPEND);
}
else
{
m_pIFileTest = IFILEMGR_OpenFile(m_pIFileMgrTest, "mylog.log", _OFM_CREATE);
}
if (NULL == m_pIFileTest)
{
return;
}
IFILE_Write(m_pIFileTest, pBuf, (sizeof(char) * (STRLEN(pBuf) + 1)));
IFILE_Write(m_pIFileTest, "\n", 1);
IFILE_Release(m_pIFileTest);
IFILEMGR_Release(m_pIFileMgrTest);
if (NULL != pBuf)
{
free(pBuf);
pBuf = NULL;
}
if (NULL != pBufForLine)
{
free(pBufForLine);
pBufForLine = NULL;
}
}
void LogToFileEx(const char *pFileName, const int nLine, const char *format, ...)
{
IFileMgr *m_pIFileMgrTest;
IFile *m_pIFileTest;
char *pFindFileName = NULL;
char *pBuf = NULL;
char *pBufForLine = NULL;
IShell* pIShell;
va_list arglist;
char tmpbuf[256];
va_start(arglist, format);
VSNPRINTF( tmpbuf, sizeof(tmpbuf), format, arglist );
pIShell = ((AEEApplet*)GETAPPINSTANCE())->m_pIShell;
pBuf = (char *)malloc(256);
pBufForLine = (char *)malloc(16);
pFindFileName = STRRCHR(pFileName, '\\');
pFindFileName++;
if (NULL == pFindFileName)
{
return;
}
STRCPY(pBuf, pFindFileName);
SPRINTF(pBufForLine, " %d ", nLine);
STRCAT(pBuf, pBufForLine);
STRCAT(pBuf, tmpbuf);
ISHELL_CreateInstance(pIShell, AEECLSID_FILEMGR, (void **)&m_pIFileMgrTest);
if (NULL == m_pIFileMgrTest)
{
return;
}
if (SUCCESS == IFILEMGR_Test(m_pIFileMgrTest, "mylog.log"))
{
m_pIFileTest = IFILEMGR_OpenFile(m_pIFileMgrTest, "mylog.log", _OFM_APPEND);
}
else
{
m_pIFileTest = IFILEMGR_OpenFile(m_pIFileMgrTest, "mylog.log", _OFM_CREATE);
}
if (NULL == m_pIFileTest)
{
return;
}
IFILE_Write(m_pIFileTest, pBuf, (sizeof(char) * (STRLEN(pBuf) + 1)));
IFILE_Write(m_pIFileTest, "\n", 1);
IFILE_Release(m_pIFileTest);
IFILEMGR_Release(m_pIFileMgrTest);
if (NULL != pBuf)
{
free(pBuf);
pBuf = NULL;
}
if (NULL != pBufForLine)
{
free(pBufForLine);
pBufForLine = NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -