boost::iostreams::gzip_compressor
을 사용하여 즉시 부스트 로그 라이브러리를 사용하여 만든 로그 파일을 압축하려고합니다. 따라서 BOOST_LOG()
으로 전화하면 출력이 즉석에서 압축됩니다. 여기에 지금까지 시도 무엇 : 나는 어떻게 든 하나 1) 싱크 전체 filtering_ostream을 두어야 느낌, 바로 file
또는압축기 사용 방법 Boost :: Iostreams 필터를 Boost :: Log의 싱크대로 사용하십시오.
2) 어떻게 든 로거 싱크를 밀어 대신하지를 얻을 수
#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 < 10; i++) {
out << "Hello world! " << i << std::endl; // compresses OK
}
sink->locked_backend()->add_stream(file);
// Register the sink in the logging core
boost::log::core::get()->add_sink(sink);
}
int main()
{
init();
boost::log::sources::logger lg;
for(int i = 0; i < 10; i++)
BOOST_LOG(lg) << "Bye world!" << std::endl; // Does not compress
return 0;
}
filtering_ostream
에 file
이 있습니다.
나를 올바른 방향으로 안내 할 수 있습니까? 감사!
+1 : 당신이 C++ 11 컴파일러가없는 경우
, 당신은, 일반 펑로 (컴파일되지 않은 및 검증되지 않은) 같은 것을 같은 일을 할 수 있습니다 :) – tank