未写入提升日志文件
boost log file not written to
我已经在boost日志上挣扎了一段时间了——我得到了他们写日志文件的简单示例(http://boost-log.sourceforge.net/libs/log/example/doc/tutorial_file.cpp)。然而,当我试图将该代码复制到"Logger"类中时,我无法将其写入日志文件。我可以看到文件default.log
被创建,但里面什么都没有
我是debian 7 64位。一切编译精细-编译行是:
g++ -o build/Logger.o -c -std=c++11 -Wall -g -O0 -DBOOST_LOG_DYN_LINK -DDEBUG src/Logger.cpp
g++ -o build/logtest build/Logger.o -lboost_log -lboost_log_setup -lboost_date_time -lboost_thread -lboost_wave -lboost_regex -lboost_program_options
这是我的代码:
Logger.cpp
/*
* Logger.cpp
*
* Created on: 2011-01-17
* Author: jarrett
*/
#include "Logger.h"
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
namespace dhlogging {
Logger::Logger(std::string fileName)
{
initialize(fileName);
}
Logger::Logger(Logger const&)
{
}
Logger::~Logger()
{
}
Logger* Logger::logger_ = nullptr;
Logger* Logger::getInstance(std::string logFile)
{
if ( Logger::logger_ == nullptr ) {
logging::add_file_log( logFile );
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
logging::add_common_attributes();
Logger::logger_ = new Logger(logFile);
}
return Logger::logger_;
}
void Logger::initialize(std::string fileName)
{
BOOST_LOG(log_) << "Hello, World!";
BOOST_LOG_SEV(log_, info) << "Hello, World2!";
}
void Logger::logInfo(std::string message)
{
BOOST_LOG_SEV(log_, info) << message;
}
void Logger::logDebug(std::string message)
{
BOOST_LOG_SEV(log_, debug) << message;
}
void Logger::logWarn(std::string message)
{
BOOST_LOG_SEV(log_, warning) << message;
}
void Logger::logError(std::string message)
{
BOOST_LOG_SEV(log_, error) << message;
}
void Logger::logFatal(std::string message)
{
BOOST_LOG_SEV(log_, fatal) << message;
}
}
int main(int, char*[])
{
logging::add_common_attributes();
using namespace logging::trivial;
dhlogging::Logger::getInstance()->logInfo("himom");
return 0;
}
Logger.h
/*
* Logger.h
*
* Created on: 2011-01-17
* Author: jarrett
*/
#ifndef LOGGER_H_
#define LOGGER_H_
#include <map>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
using namespace logging::trivial;
namespace dhlogging {
class Logger {
public:
static Logger* getInstance(std::string logFile = "default.log");
void logInfo(std::string message);
void logDebug(std::string message);
void logWarn(std::string message);
void logError(std::string message);
void logFatal(std::string message);
private:
Logger(std::string fileName);
Logger(Logger const&);
Logger& operator=(Logger const&);
virtual ~Logger();
void initialize(std::string fileName);
src::severity_logger< severity_level > log_;
static Logger* logger_; // singleton instance
};
}
#endif /* LOGGER_H_ */
创建文件日志时需要使用此属性
keywords::auto_flush = true
这样日志条目就可以立即写入。默认情况下,当文件超出范围时,文件记录器似乎会写入文件,或者在其他一些神秘的地方,文档中没有提到任何关于
相关文章:
- 加快在C++中读取/处理日志文件的速度
- 如何将消息时间戳写入日志文件?
- 分析包含 NMEA 句子的日志文件C++
- 如何从日志文件中抓取状态代码?(在 C++ 中)
- 未创建日志文件
- 尝试使用 EvtSetChannelConfigProperty() 函数更新最大事件日志文件大小时插入的错误值
- 提升日志:文件轮换
- POSIX C/C++日志文件(VEX V5 Brain)
- boost日志文件无法创建sample.log文件
- 哪个更适合从C++写入敏感的日志文件,在文件描述符上写()或文件上的fprintf()?
- 如何编写日志文件,以便可以使用记事本实时读取它以进行C++
- 如何在QT中使用DEBUG对齐日志文件中的数据?
- Qt - 如何在 30 天后删除日志文件,文件名不固定
- Mac OS X:应用程序可以创建日志文件
- 将断言消息写入日志文件
- 检查日志文件以找出 vcredist.exe 安装失败的原因
- C++同时记录到控制台和日志文件
- 无法创建将包含日志文件的文件夹
- (罗)如何使用相对路径保存日志文件
- boost::log关闭日志文件并打开一个新文件