怎么做网站的后台维护,单页设计多少钱,苏州seo网络优化公司,酒类网站建设最近项目需要简单输出日志#xff0c;用巨大的日志类未免繁琐#xff0c;于是写了这个简单的日志函数#xff0c;带日期#xff0c;MFC下可以直接使用。
直接上代码#xff1a;
template typename T
std::string ConvertToStringS(T value)
{std::stringstream …最近项目需要简单输出日志用巨大的日志类未免繁琐于是写了这个简单的日志函数带日期MFC下可以直接使用。
直接上代码
template typename T
std::string ConvertToStringS(T value)
{std::stringstream ss;ss value;return ss.str();
}static std::string LogInfo(const std::string sInfo, bool s_bTimePrefix true)
{SYSTEMTIME sysTime { 0 };GetLocalTime(sysTime);std::string sFinalInfo;if (s_bTimePrefix){sFinalInfo [ ConvertToStringS(sysTime.wMonth) ConvertToStringS(sysTime.wDay) - \ConvertToStringS(sysTime.wHour) - ConvertToStringS(sysTime.wMinute) - ConvertToStringS(sysTime.wSecond) - \ConvertToStringS(sysTime.wMilliseconds) ]: sInfo;}else{sFinalInfo sInfo;}return sFinalInfo;
}static int LogInfoToFile(const std::string sInfo, const std::string sFilePath, bool bAppend false)
{std::vectorstd::string vInfos;vInfos.push_back(LogInfo(sInfo));return SaveTXTUtf8S(vInfos, sFilePath, bAppend);
}
使用方法如下 //输出日志代表成功进入std::string sTmpPath getenv(Temp);// 目录结尾if (sTmpPath.length() sTmpPath[sTmpPath.length() - 1] ! \\){sTmpPath \\;}//路径std::string sLogPath sTmpPath xxx.log;LogInfoToFile(exe成功启动..., sLogPath);
使用效果如下图 谨此记录。