我的应用程序当前登录的一个非常简单的方法:限制文件流的文件大小?
void Log::create(const std::string& path, bool append)
{
if(append)
m_log.open(path.c_str(),std::ios_base::out | std::ios_base::app);
else
m_log.open(path.c_str(),std::ios_base::out | std::ios_base::trunc);
}
std::ofstream& Log::get()
{
return m_log;
}
void Log::write(const std::string& what)
{
get() << "[" << TimeOfDay::getDate() << "] ";
get() << what << std::endl;
}
void Log::write(const std::string& where, const std::string& what)
{
get() << "[" << TimeOfDay::getDate() << "] ";
get() << "[" << where << "] " << what << std::endl;
}
std::ofstream& Log::write()
{
get() << "[" << TimeOfDay::getDate() << "] ";
return get();
}
std::ofstream Log::m_log;
此应用程序的服务器上运行。现在,如果日志超过了某个文件大小,我想停止日志记录。
有没有办法做到这一点,没有提升或其他图书馆?
感谢
难道你不能通过在各种'write()'重载中递增计数器来记录写入的行数吗? Boost.Filesystem具有['file_size'](http://www.boost.org/libs/filesystem/doc/reference.html#file_size)函数,可以实现您想要的功能。 MSVC 2013附带一个基于Boost的''实现,因此如果您使用该编译器,它应该提供相同的功能。 –
Praetorian