日期:2014-05-16 浏览次数:20752 次
static int LogPrint(char *pcStrData)
{
char acDate[16];
char acLogName[30];
char acLogPath[100];
char acLogPathName[120];
FILE *pFd;
GetUTC(acDate);
/* log文件名字 */
//strncpy(cLogName, cDate, 10);/* 取年月日小时为文件名 */
//strncpy(acLogName, acDate, 14);/* 取年月日小时分秒为文件名 */
strncpy(acLogName, acDate, 8);/* 取年月日小时为文件名 */
acLogName[8] = '\0';
strcat(acLogName, ".log");
/* 获取路径 */
getcwd(acLogPath, sizeof(acLogPath));
/* 获得完整路径 */
sprintf(acLogPathName, "%s/log/", acLogPath);
/* 创建文件夹 */
mkdir(acLogPathName, 0777);
strcat(acLogPathName, acLogName);
pFd = fopen(acLogPathName, "a+");
if (pFd == NULL)
{
DBG_PRINT("can not create log file:%s \n", acLogPathName);
return -1;
}
GetUTC(acDate);
fwrite(acDate, 14, 1, pFd);/* 年月日时分秒 */
fwrite(" ", 1, 1, pFd);
fwrite(pcStrData, strlen(pcStrData), 1, pFd);
fclose(pFd);
//fwrite("\n", 1, 1, pFd);
return strlen(pcStrData) + 14 + 1;
}