logging - boost::filesystem::create_directories: 功能未实现
问题描述
我正在尝试使用 Boost 1.76.0 在 ubuntu 18.04 中运行“旋转文本文件”日志示例,编译已成功完成,但是当我尝试运行代码时,它给了我以下错误:
失败:boost::filesystem::create_directories:功能未实现:“/test/build/logs”
代码是:
//#define BOOST_LOG_DYN_LINK 1
#include <stdexcept>
#include <string>
#include <iostream>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/log/common.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords;
using boost::shared_ptr;
enum { LOG_RECORDS_TO_WRITE = 10000 };
int main(int argc, char* argv[])
{
try
{
// Create a text file sink
typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
shared_ptr< file_sink > sink(new file_sink(
keywords::file_name = "file.log", // file name pattern
keywords::target_file_name = "%Y%m%d_%H%M%S_%5N.log", // file name pattern
keywords::rotation_size = 16384 // rotation size, in characters
));
// Set up where the rotated files will be stored
sink->locked_backend()->set_file_collector(sinks::file::make_collector(
keywords::target = "logs", // where to store rotated files
keywords::max_size = 16 * 1024 * 1024, // maximum total size of the stored files, in bytes
keywords::min_free_space = 100 * 1024 * 1024, // minimum free space on the drive, in bytes
keywords::max_files = 512 // maximum number of stored files
));
// Upon restart, scan the target directory for files matching the file_name pattern
sink->locked_backend()->scan_for_files();
sink->set_formatter
(
expr::format("%1%: [%2%] - %3%")
% expr::attr< unsigned int >("RecordID")
% expr::attr< boost::posix_time::ptime >("TimeStamp")
% expr::smessage
);
// Add it to the core
logging::core::get()->add_sink(sink);
// Add some attributes too
logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock());
logging::core::get()->add_global_attribute("RecordID", attrs::counter< unsigned int >());
// Do some logging
src::logger lg;
for (unsigned int i = 0; i < LOG_RECORDS_TO_WRITE; ++i)
{
BOOST_LOG(lg) << "Some log record";
}
return 0;
}
catch (std::exception& e)
{
std::cout << "FAILURE: " << e.what() << std::endl;
return 1;
}
}
CMakeList.txt 文件是:
cmake_minimum_required (VERSION 3.8)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
project ("cpMain")
# we will use static libs
set(Boost_USE_STATIC_LIBS ON) # link statically
#ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK) # or, link dynamically
# Boost::log required Boost version >= 1.76.0
find_package(Boost 1.76 COMPONENTS log REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
# Define Sources
set(SRC_FILES
"main.cpp"
)
# Add source to this project's executable.
add_executable (cpMain
${SRC_FILES})
# Link your application with OpenCV libraries
target_link_libraries (cpMain
${Boost_LIBRARIES}
)
谢谢您的帮助,
路易斯
解决方案
推荐阅读
- ios - 无法使用 AWSMobileClient iOS 登录。获取 AWSMobileClientError 错误 13
- html - 如何使用 CSS 删除输入字段的最后一个字母的字母间距?
- node.js - 使用 nodejs 从 cloud firestore 获取数据需要很长时间
- android - 运行模拟器的架构
- spring-boot - 连接到 IDE 中现有的 hsqldb 实例
- python - 将变量设置为 True 或 False 有什么意义?
- python - Pandas:将数据框的单元格与不同列的内容进行比较并复制相邻数据
- php - PHP:在 html 文件中使用 javascript 时,我可以在全局范围内分配 var mythis=this。PHP中有类似的方法吗?
- bash - 是否可以在 bash 脚本中剪切特定列并显示该列的重复出现次数?
- r - 使用 glmer 的模型无法收敛和多个警告