[Boost-bugs] [Boost C++ Libraries] #12867: log library extensions

Subject: [Boost-bugs] [Boost C++ Libraries] #12867: log library extensions
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-02-24 15:28:27


#12867: log library extensions
------------------------------+--------------------------
 Reporter: vgrinenko@… | Owner: andysem
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: log
  Version: Boost 1.57.0 | Severity: Optimization
 Keywords: |
------------------------------+--------------------------
 '''Please forward this request to Mr. Andrey Semashev.'''


 Dear Andrey,

 in our company we have decided to use the boost log in our applications.
 We need 2 additional extensions for the file backend:
 1. we want to delete the log files after specific amount of time
 2. we want to make some logs un-deleteable, for example to change the
 log name in some circumstance, for example in case if the record with
 severity “fatal” has been written.

 For this I have added to your text_file_backend.hpp/ text_file_backend.cpp
 two additional predicates and some code for these predicates support.

 The time_based_deleting_predicate in my application is implemented as:


 {{{
 m_sink->locked_backend()->set_file_collector(sinks::polytec_ext::file::make_collector(
                                 keywords::target = dir
                                 , keywords::max_size = maxSize
                                 , keywords::time_based_deleting =
 [=](std::time_t time)
                         {
                                 if (deletingInterval.count() == 0)
                                         return false;
                                 std::chrono::system_clock::time_point now
 = std::chrono::system_clock::now();
                                 std::time_t latest =
 std::chrono::system_clock::to_time_t(now) - deletingInterval.count();
                                 return latest > time;
                         }));

 }}}

 The record_based_renaming_predicate is implemented as:


 {{{
 m_sink->locked_backend()->set_record_based_renaming(
                                 [=](logging::record_view const& rec,
 boost::filesystem::path& path)
                         {
                                 auto level = boost::log::extract<
 severity_level >("Severity", rec);
                                 if (level && severity_level::fatal ==
 level.get())
                                 {
                                         auto fname = path.stem();
                                         bool hasErrorSuffix =
 boost::algorithm::ends_with(fname.c_str(), L"_ERROR");
                                         if (!hasErrorSuffix)
                                         {
                                                 auto newFname =
 path.parent_path() /
 boost::filesystem::path(path.stem().wstring() + L"_ERROR" +
 path.extension().wstring());
                                                 path = newFname;
                                                 return true;
                                         }
                                 }
                                 return false;
                         });

 }}}


 If you are finding these features useful for other library users and
 merging (may be with some improvements accordingly to your vision of the
 library future) with the library code it will make me a pleasure :-) and
 we will remove our implementation and will use the library “as is”.
 The ZIP file with my hpp an cpp is attached to the request. I have used
 1.57 vesrsion of boost.
 Thank you for your attention and best regards.
 Victor Grinenko.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12867>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-24 15:32:05 UTC