最简单的C++日志类

#pragma once

#include "stdafx.h"
#include   
#include   
#include   
#include 

using namespace std;

class EasyLog
{
public:
	static void Write(std::string log) {  
		try
		{    
			std::ofstream ofs;  
			time_t t = time(0);  
			char tmp[64];  
			strftime(tmp, sizeof(tmp), "[%Y-%m-%d %X]", localtime(&t));  
			ofs.open("C:\\lxw.log", std::ofstream::app);  
			ofs << tmp << " - ";  
			ofs.write(log.c_str(), log.size());  
			ofs << std::endl;  
			ofs.close();         
		}
		catch(...)
		{
		} 
	}
};

调用

 EasyLog::Write("test");

你可能感兴趣的:(C++,c++,开发语言)