afLog.cpp
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:3k
源码类别:
其他游戏
开发平台:
Visual C++
- // afLog.cpp: implementation of the afLog class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "afLog.h"
- #include <direct.h>
- #include <stdarg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- char afLog::fileName[1024];
- void afLog::init(const char* nLogFileName)
- {
- _getcwd(fileName, _MAX_PATH);
- strcat(fileName, "\");
- strcat(fileName, nLogFileName);
- FILE* fp = fopen(fileName, "a+");
- if(fp==NULL)
- return;
- fprintf(fp, "nnn");
- fclose(fp);
- info("================================================================");
- info("");
- info(" Log opened");
- info("");
- info("================================================================");
- info("");
- }
- void afLog::info(const char *szFormat, ...)
- {
- char buffer[512], buffer2[512]; // Large buffer
- // Format the input string
- va_list pArgs;
- va_start(pArgs, szFormat);
- vsprintf(buffer, szFormat, pArgs);
- va_end(pArgs);
- char tmpbuf[128];
- time_t ltime;
- struct tm today;
- time(<ime);
- today = *localtime(<ime);
- strftime(tmpbuf, 128, "%Y-%m-%d %H:%M:%S", &today);
- sprintf(buffer2, "%s INFO: %s", tmpbuf, buffer);
- FILE* fp = fopen(fileName, "a+");
- if(fp==NULL)
- return;
- fprintf(fp, buffer2);
- fprintf(fp, "n");
- fclose(fp);
- }
- void afLog::warning(const char *szFormat, ...)
- {
- char buffer[512], buffer2[512]; // Large buffer
- // Format the input string
- va_list pArgs;
- va_start(pArgs, szFormat);
- vsprintf(buffer, szFormat, pArgs);
- va_end(pArgs);
- char tmpbuf[128];
- time_t ltime;
- struct tm today;
- time(<ime);
- today = *localtime(<ime);
- strftime(tmpbuf, 128, "%Y-%m-%d %H:%M:%S", &today);
- sprintf(buffer2, "%s WARNING: %s", tmpbuf, buffer);
- FILE* fp = fopen(fileName, "a+");
- if(fp==NULL)
- return;
- fprintf(fp, buffer2);
- fprintf(fp, "n");
- fclose(fp);
- }
- void afLog::error(const char *szFormat, ...)
- {
- char buffer[512], buffer2[512]; // large buffers
- // format the input string
- va_list pArgs;
- va_start(pArgs, szFormat);
- vsprintf(buffer, szFormat, pArgs);
- va_end(pArgs);
- char tmpbuf[128];
- time_t ltime;
- struct tm *today;
- time(<ime);
- today = localtime(<ime);
- strftime(tmpbuf, 128, "%Y-%m-%d %H:%M:%S", today);
- sprintf(buffer2, "%s ERROR: %s", tmpbuf, buffer);
- FILE* fp = fopen(fileName, "a+");
- if(fp==NULL)
- return;
- fprintf(fp, buffer2);
- fprintf(fp, "n");
- fclose(fp);
- }
- void afLog::trace(const char *szFormat, ...)
- {
- szFormat;
- #ifdef _DEBUG
- char buffer[512]; // large buffer
- // format the input string
- va_list pArgs;
- va_start(pArgs, szFormat);
- vsprintf(buffer, szFormat, pArgs);
- va_end(pArgs);
- OutputDebugString(buffer);
- #endif //_DEBUG
- }