mirror of
https://github.com/boostorg/log.git
synced 2026-02-09 11:12:38 +00:00
Extracted text_multifile_backend implementation to a separate file.
This commit is contained in:
@@ -54,7 +54,6 @@
|
||||
#include <boost/log/exceptions.hpp>
|
||||
#include <boost/log/attributes/time_traits.hpp>
|
||||
#include <boost/log/sinks/text_file_backend.hpp>
|
||||
#include <boost/log/sinks/text_multifile_backend.hpp>
|
||||
|
||||
#if !defined(BOOST_LOG_NO_THREADS)
|
||||
#include <boost/thread/locks.hpp>
|
||||
@@ -1356,67 +1355,6 @@ BOOST_LOG_API uintmax_t text_file_backend::scan_for_files(file::scan_method meth
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Multifile sink backend implementation
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//! Sink implementation data
|
||||
struct text_multifile_backend::implementation
|
||||
{
|
||||
//! File name composer
|
||||
file_name_composer_type m_FileNameComposer;
|
||||
//! Base path for absolute path composition
|
||||
const filesystem::path m_BasePath;
|
||||
//! File stream
|
||||
filesystem::ofstream m_File;
|
||||
|
||||
implementation() :
|
||||
m_BasePath(filesystem::current_path())
|
||||
{
|
||||
}
|
||||
|
||||
//! Makes relative path absolute with respect to the base path
|
||||
filesystem::path make_absolute(filesystem::path const& p)
|
||||
{
|
||||
return filesystem::absolute(p, m_BasePath);
|
||||
}
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
BOOST_LOG_API text_multifile_backend::text_multifile_backend() : m_pImpl(new implementation())
|
||||
{
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
BOOST_LOG_API text_multifile_backend::~text_multifile_backend()
|
||||
{
|
||||
delete m_pImpl;
|
||||
}
|
||||
|
||||
//! The method sets the file name composer
|
||||
BOOST_LOG_API void text_multifile_backend::set_file_name_composer_internal(file_name_composer_type const& composer)
|
||||
{
|
||||
m_pImpl->m_FileNameComposer = composer;
|
||||
}
|
||||
|
||||
//! The method writes the message to the sink
|
||||
BOOST_LOG_API void text_multifile_backend::consume(record_view const& rec, string_type const& formatted_message)
|
||||
{
|
||||
typedef file_char_traits< string_type::value_type > traits_t;
|
||||
if (!m_pImpl->m_FileNameComposer.empty())
|
||||
{
|
||||
filesystem::path file_name = m_pImpl->make_absolute(m_pImpl->m_FileNameComposer(rec));
|
||||
filesystem::create_directories(file_name.parent_path());
|
||||
m_pImpl->m_File.open(file_name, std::ios_base::out | std::ios_base::app);
|
||||
if (m_pImpl->m_File.is_open())
|
||||
{
|
||||
m_pImpl->m_File.write(formatted_message.data(), static_cast< std::streamsize >(formatted_message.size()));
|
||||
m_pImpl->m_File.put(traits_t::newline);
|
||||
m_pImpl->m_File.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
||||
|
||||
Reference in New Issue
Block a user