我正在尝试通过利用来即时压缩使用Boost Log库创建的日志文件boost::iostreams::gzip_compressor.因此,当我打电话时BOOST_LOG(),输出会即时压缩.这是我到目前为止所尝试的:
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sources/logger.hpp>
void init()
{
// Construct the sink
typedef boost::log::sinks::synchronous_sink< boost::log::sinks::text_ostream_backend > text_sink;
boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink >();
boost::shared_ptr< std::ofstream > file = boost::make_shared< std::ofstream >(
"sample.gz", std::ios_base::out | std::ios_base::binary );
boost::iostreams::filtering_ostream out;
out.push( boost::iostreams::gzip_compressor() );
out.push( *(file.get()) );
for( int i = 0; i < …Run Code Online (Sandbox Code Playgroud)