uccessful,memory size is: %ld",
TEST_CASE_MAX_FILE_LEN);
pFile = fopen(szFileName, "r");
if(NULL == pFile)
{
fprintf(stderr, "open file failed.");
Write_Log(LOG_TYPE_ERROR, "Open file %s failed. program exit!", szFileName);
return;
}
Write_Log(LOG_TYPE_INFO, "Open file %s successful.", szFileName);
fread(pFieldContent, 1, TEST_CASE_MAX_FILE_LEN, pFile);
pFieldContent[TEST_CASE_MAX_FILE_LEN -1] = '/0';
fclose(pFile);
printf("The file %s content is: /n%s/n", szFileName, pFieldContent);
Write_Log(LOG_TYPE_INFO, "The file %s content is: /n%s/n", szFileName, pFieldContent);
}
/*********************************************************************
* 函数名称:void Write_Log(unsigned int uiLogType, char *pstrFmt, ...)
* 说明:日志写函数,支持变长参数
* 调用者:任何需要写日志的地方
* 输入参数:
* unsigned iType -- 日志类别
* char *pstrFmt -- 日志内容
* ... -- 变长参数
* 输出参数:
* 无
* 返回值:
* void --
* 作者: duanyongxing
* 时间 : 2009-10-11
*********************************************************************/
void Write_Log(unsigned int uiLogType, char *pstrFmt, ...)
{
#if _LOG_WRITE_STATE_ /* 写日志与否的编译开关*/
LOG_DATA data;
time_t curTime;
struct tm *mt;
va_list v1;
memset(&data, 0, sizeof(LOG_DATA));
va_start(v1, pstrFmt);
_vsnprintf(data.strText, MAX_LOGTEXT_LEN, pstrFmt, v1);
va_end(v1);
data.iType = uiLogType;
curTime = time(NULL);
mt = localtime(&curTime);
strftime(data.strDate, sizeof(data.strDate), "%Y-%m-%d", mt);
strftime(data.strTime, sizeof(data.strTime), "%H:%M:%S", mt);
Write_Log_Text(&data);
#endif _LOG_WRITE_STATE_
}
/*********************************************************************
* 函数名称:int GetLogPath(char *pStrPath)
* 说明:获取日志文件路径
* 调用者:Write_Log_Text
* 输入参数:
* 无
* 输出参数:
* char *pStrPath
* 返回值:
* int -- LOG_FAILED: 失败
* -- LOG_SUCCESS: 成功
* 作者: duanyongxing
* 时间 : 2009-10-11
*********************************************************************/
int GetLogPath(char *pStrPath)
{
if(NULL == pStrPath)
{
return LOG_FAILED;
}
int iRet = 0;
time_t curTime = time(NULL);
struct tm *mt = localtime(&curTime);
/* 根据日期组成文件夹名称*/
sprintf(pStrPath, "%s//%d%02d%02d", g_LogRootPath, mt->tm_year + 1900,
mt->tm_mon + 1, mt->tm_mday);
iRet = Create_LogDir(pStrPath);
return iRet;
}
/*********************************************************************
* 函数名称:int GetLogFileName(int iLogType, const char *pStrPath, char *pStrName)
* 说明:获取日志文件名
* 调用者:Write_Log_Text
* 输入参数:
* int iLogType -- 日志类型 3种:INFO(0)/ERROR(1)/SYSTEM(2)
* const char *pStrPath -- 日志路径 由GetLogPath得到
* 输出参数:
* char *pStrName -- 日志文件名
* 返回值:
* int -- LOG_FAILED: 失败
* -- LOG_SUCCESS: 成功
* 作者: duanyongxing
* 时间 : 2009-10-11
*********************************************************************/
int GetLogFileName(int iLogType, const char *pStrPath, char *pStrName)
{
if(NULL == pStrPath)
{
return LOG_FAILED;
}
char szLogName[MAX_FILE_PATH];
FILE *pFile = NULL;
memset(szLogName, 0, MAX_FILE_PATH);
switch (iLogType)
{
case LOG_TYPE_INFO:
sprintf(szLogName, "%s//app_info", pStrPath);
break;
case LOG_TYPE_ERROR:
sprintf(szLogName, "%s//app_error", pS |