Skip to content

Commit

Permalink
Switch from Boost log to spdlog
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed Apr 27, 2021
1 parent 5e09ee5 commit f6e440c
Show file tree
Hide file tree
Showing 67 changed files with 719 additions and 803 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ endif()

# For useful information on getting CMake to work with Boost, type the following command: `cmake --help-module FindBoost`
# or add `SET( Boost_DEBUG "ON" )` to this file to get helpful debug information when running CMake
find_package( Boost 1.60 REQUIRED filesystem iostreams log program_options serialization timer unit_test_framework )
find_package( Boost 1.60 REQUIRED filesystem iostreams program_options serialization timer unit_test_framework )

find_package( RapidJSON 1.1.0 REQUIRED )
find_package( fmt 7.1.3 REQUIRED )
find_package( spdlog 1.8.5 REQUIRED )

# Compiler options
SET( CMAKE_CXX_STANDARD 14 )
Expand Down
17 changes: 10 additions & 7 deletions conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
# Using Boost 1.72 because:
#
# * the CI is using Ubuntu 20.04, which has CMake 3.16, which only knows Boost ≤1.72 and spews warnings about higher versions
# * though it wouldn't be hard to modify the CI to use the Kitware Ubuntu CMake repos, there's little point because the code doesn't use any features after 1.60 anyway
# * though it wouldn't be hard to modify the CI to use the Kitware Ubuntu CMake repos, there's little point because the
# code doesn't use any features after 1.60 anyway
boost/1.72.0@
fmt/7.1.3@
rapidjson/1.1.0
spdlog/1.8.5@

[generators]
cmake_find_package
Expand All @@ -16,34 +19,34 @@ cmake
boost:without_exception=False
boost:without_filesystem=False
boost:without_iostreams=False # Used by gnuplot-iostream.h - consider dropping
boost:without_log=False # Without log, could drop: container, date_time, locale, thread
boost:without_program_options=False
boost:without_serialization=False
boost:without_test=False

# Secondary dependencies (ie required but only by primary dependencies)
boost:without_atomic=False
boost:without_chrono=False
boost:without_container=False
boost:without_date_time=False
boost:without_locale=False
boost:without_math=False
boost:without_random=False
boost:without_regex=False
boost:without_system=False
boost:without_thread=False
boost:without_timer=False

# boost:without_json=True # applies for more recent Boosts
# boost:without_nowide=True # applies for more recent Boosts
boost:without_container=True
boost:without_context=True
boost:without_contract=True
boost:without_coroutine=True
boost:without_date_time=True
boost:without_fiber=True
boost:without_graph=True
boost:without_graph_parallel=True
boost:without_locale=True
boost:without_log=True
boost:without_mpi=True
boost:without_python=True
boost:without_stacktrace=True
boost:without_thread=True
boost:without_type_erasure=True
boost:without_wave=True
boost:without_wave=True
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ target_link_libraries( ct_cath_superpose PUBLIC ct_common ct_uni
target_link_libraries( ct_chopping PUBLIC ct_biocore Boost::program_options )
target_link_libraries( ct_clustagglom PUBLIC ct_common Boost::program_options )
target_link_libraries( ct_cluster PUBLIC ct_common ct_options ct_seq Boost::program_options )
target_link_libraries( ct_common PUBLIC Boost::log cath_tools_gsl cath_tools_rapidjson )
target_link_libraries( ct_common PUBLIC Boost::filesystem cath_tools_gsl cath_tools_rapidjson spdlog::spdlog )
target_link_libraries( ct_display_colour PUBLIC ct_common )
target_link_libraries( ct_options PUBLIC ct_chopping ct_external_info )
target_link_libraries( ct_resolve_hits PUBLIC ct_display_colour ct_options ct_seq )
Expand Down
16 changes: 7 additions & 9 deletions source/ct_cath_cluster/cath/cath_cluster/cath_clusterer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

#include "cath_clusterer.hpp"

#include <boost/log/trivial.hpp>
#include <fstream>

#include <spdlog/spdlog.h>

#include "cath/cath_cluster/options/cath_cluster_options.hpp"
#include "cath/clustagglom/calc_complete_linkage_merge_list.hpp"
Expand All @@ -38,14 +40,11 @@
#include "cath/common/file/path_or_istream.hpp"
#include "cath/common/logger.hpp"

#include <fstream>

using namespace ::cath::clust;
using namespace ::cath::common;
using namespace ::cath::opts;

using ::boost::filesystem::path;
using ::boost::log::trivial::warning;
using ::boost::make_optional;
using ::std::ifstream;
using ::std::istream;
Expand Down Expand Up @@ -88,7 +87,7 @@ void cath::clust::perform_cluster(const cath_cluster_options &prm_opts, ///<
const strength the_max_dissim = get_max_dissim ( clust_spec, the_link_dirn );

if ( level_warning ) {
BOOST_LOG_TRIVIAL( warning ) << *level_warning;
::spdlog::warn( *level_warning );
}

// Organise the input stream
Expand All @@ -112,10 +111,9 @@ void cath::clust::perform_cluster(const cath_cluster_options &prm_opts, ///<
if ( has_names_file ) {
return get_sorting_scores( the_name_ider, props );
}
BOOST_LOG_TRIVIAL( warning )
<< "No names file has been specified. You are recommended to specify a names file ("
<< cath_cluster_input_options_block::PO_NAMES_INFILE
<< ") to ensure singletons don't get missed.";
::spdlog::warn( "No names file has been specified. You are recommended to specify a names file ({}) to ensure "
"singletons don't get missed.",
cath_cluster_input_options_block::PO_NAMES_INFILE );
return get_sorting_scores( the_name_ider );
} ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#include "cath_superposer.hpp"

#include <boost/filesystem/path.hpp>
#include <boost/log/trivial.hpp>
#include <boost/ptr_container/ptr_vector.hpp>

#include <spdlog/spdlog.h>

#include "cath/acquirer/alignment_acquirer/alignment_acquirer.hpp"
#include "cath/acquirer/pdbs_acquirer/pdbs_acquirer.hpp"
#include "cath/acquirer/selection_policy_acquirer/selection_policy_acquirer.hpp"
Expand Down Expand Up @@ -83,7 +84,7 @@ void cath_superposer::superpose(const cath_superpose_options &prm_cath_superpose
}
else {
if ( ! aln_outputters.empty() ) {
BOOST_LOG_TRIVIAL( warning ) << "Ignoring alignment output options because there is no alignment (and the cake is a lie)";
::spdlog::warn( "Ignoring alignment output options because there is no alignment (and the cake is a lie)" );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@

#include "cath_superposer.hpp"

#include <boost/log/trivial.hpp>
#include <fstream>
#include <sstream>

#include <boost/test/unit_test.hpp>

#include <spdlog/spdlog.h>

#include "cath/cath_superpose/options/cath_superpose_options.hpp"
#include "cath/chopping/domain/domain.hpp"
#include "cath/common/argc_argv_faker.hpp"
Expand All @@ -34,9 +38,6 @@
#include "cath/test/predicate/files_equal.hpp"
#include "cath/test/predicate/istream_and_file_equal.hpp"

#include <fstream>
#include <sstream>

using namespace ::cath;
using namespace ::cath::common;
using namespace ::cath::opts;
Expand Down Expand Up @@ -122,11 +123,9 @@ void cath::test::cath_superposer_test_suite_fixture::check_cath_superposer_use_c
if ( prm_outputs_to_temp_file ) {
const auto output_file = temp_output_filename;
if ( ! exists( output_file ) ) {
BOOST_LOG_TRIVIAL( error ) << "cath-superpose command did not produce output file. Got stdout is: \""
<< test_stdout.str()
<< "\". Got stderr is: \""
<< test_stderr.str()
<< "\"";
::spdlog::error( R"(cath-superpose command did not produce output file. Got stdout is: "{}". Got stderr is: "{}")",
test_stdout.str(),
test_stderr.str() );
}

// Blank out the version number in the superposition
Expand Down
5 changes: 3 additions & 2 deletions source/ct_chopping/cath/chopping/region/regions_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

#include <boost/algorithm/cxx11/any_of.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/log/trivial.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>

#include <spdlog/spdlog.h>

#include "cath/biocore/residue_id.hpp"
#include "cath/chopping/region/region.hpp"
#include "cath/common/algorithm/transform_build.hpp"
Expand Down Expand Up @@ -205,6 +206,6 @@ void cath::chop::warn_if_specified_regions_remain_unseen(const regions_limiter &
) {
const auto warn_str = warn_str_if_specified_regions_remain_unseen( prm_regions );
if ( warn_str ) {
BOOST_LOG_TRIVIAL( warning ) << *warn_str;
::spdlog::warn( *warn_str );
}
}
41 changes: 23 additions & 18 deletions source/ct_cluster/cath/cluster/file/cluster_membership_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@

#include "cluster_membership_file.hpp"

#include <boost/log/trivial.hpp>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

#include <boost/utility/string_ref.hpp>

#include <spdlog/fmt/ostr.h>
#include <spdlog/spdlog.h>

#include "cath/cluster/cluster_type_aliases.hpp"
#include "cath/cluster/old_cluster_data.hpp"
#include "cath/common/boost_addenda/log/log_to_ostream_guard.hpp"
Expand All @@ -33,11 +40,6 @@
#include "cath/common/string/string_parse_tools.hpp"
#include "cath/seq/seq_seg_run_parser.hpp"

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

using namespace ::cath;
using namespace ::cath::clust;
using namespace ::cath::common;
Expand Down Expand Up @@ -68,26 +70,29 @@ static inline void warn_if_neccessary(const clust_entry_problem &prm_problem,
switch ( prm_problem ) {
case ( clust_entry_problem::REPEAT ) : {
if ( ! prm_warned_duplicate ) {
BOOST_LOG_TRIVIAL( warning ) << "Skipping entry "
<< prm_entry_name << " (in cluster "
<< prm_cluster_name << ") because it duplicates a previous entry in the same cluster-membership input data. Will not warn about any further duplicate entries."
<< ( prm_extra_info ? " - " + *prm_extra_info : string{} );
::spdlog::warn(
"Skipping entry {} (in cluster {}) because it duplicates a previous entry in the same "
"cluster-membership input data. Will not warn about any further duplicate entries.{}",
prm_entry_name,
prm_cluster_name,
( prm_extra_info ? " - " + *prm_extra_info : string{} ) );
prm_warned_duplicate = true;
}
break;
}
case ( clust_entry_problem::CLASH ) : {
BOOST_LOG_TRIVIAL( warning ) << "Skipping entry "
<< prm_entry_name << " (in cluster "
<< prm_cluster_name << ") because it clashes with a previous entry in the same cluster-membership input data"
<< ( prm_extra_info ? " - " + *prm_extra_info : string{} );
::spdlog::warn( "Skipping entry {} (in cluster {}) because it clashes with a previous entry in the "
"same cluster-membership input data{}",
prm_entry_name,
prm_cluster_name,
( prm_extra_info ? " - " + *prm_extra_info : string{} ) );
break;
}
case ( clust_entry_problem::PARSE_ERROR ) : {
BOOST_LOG_TRIVIAL( warning ) << "Problem parsing segments from entry "
<< prm_entry_name << " (in cluster "
<< prm_cluster_name << ")"
<< ( prm_extra_info ? " - " + *prm_extra_info : string{} );
::spdlog::warn( "Problem parsing segments from entry {} (in cluster {}){}",
prm_entry_name,
prm_cluster_name,
( prm_extra_info ? " - " + *prm_extra_info : string{} ) );
break;
}
case ( clust_entry_problem::NONE ) : {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.

//#include <boost/log/trivial.hpp> // ***** TEMPORARY *****
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>
#include <boost/test/unit_test.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,48 @@
/// You should have received a copy of the GNU General Public License
/// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "log_to_ostream_guard.hpp"
#include <iostream>

#include <boost/core/null_deleter.hpp>
#include <boost/shared_ptr.hpp>
#include <spdlog/sinks/ostream_sink.h>

#include "cath/common/boost_addenda/log/log_to_ostream_guard.hpp"

using namespace ::cath;
using namespace ::std;

using ::boost::null_deleter;
using ::std::make_shared;
using ::std::ostream;
using ::std::shared_ptr;

/// \brief Ctor for log_to_ostream_guard
log_to_ostream_guard::log_to_ostream_guard(ostream &prm_ostream ///< TODOCUMENT
) {
if ( &prm_ostream != &cerr ) {
// Construct a sink
boost_log_sink_bsptr = boost::make_shared<sink_t>();
namespace sinks = ::spdlog::sinks;

// Get a (non-deleting) shared_ptr to the ostream and add it to the sink
boost::shared_ptr<ostream> stream_bsptr( &prm_ostream, null_deleter() );
boost_log_sink_bsptr->locked_backend()->add_stream( stream_bsptr );
/// \brief Ctor for log_to_ostream_guard
///
/// \param prm_ostream The ostream to which logging should temporarily be redirected for the log_to_ostream_guard's lifetime
log_to_ostream_guard::log_to_ostream_guard( ostream &prm_ostream ) : logger_shptr{ ::spdlog::default_logger() } {
// The previous logger is being stored in logger_shptr
// So now set a new logger to log to prm_ostream
::spdlog::set_default_logger( make_shared<::spdlog::logger>(
"", shared_ptr<::sinks::sink>( make_shared<::sinks::ostream_sink_mt>( prm_ostream ) ) ) );

// Register the sink in the logging core
boost::log::core::get()->add_sink( boost_log_sink_bsptr );
}
// Change the format to just contain the message
::spdlog::default_logger()->set_pattern( "%v" );
}

/// \brief Virtual empty dtor for log_to_ostream_guard
log_to_ostream_guard::~log_to_ostream_guard() noexcept {
// If this log_to_ostream_guard has added a sink to the Boost Log core
// then try to remove it now
// If this log_to_ostream_guard has changed the default logger, reset it
try {
remove_log_sink();
reset_default_logger();
}
// ...but don't let any exceptions escape the destructor
catch (...) {
catch ( ... ) {
}
}

/// \brief TODOCUMENT
void log_to_ostream_guard::remove_log_sink() {
if ( boost_log_sink_bsptr ) {
boost::log::core::get()->remove_sink( boost_log_sink_bsptr );
boost_log_sink_bsptr.reset();
/// \brief Reset the default logger
void log_to_ostream_guard::reset_default_logger() {
if ( logger_shptr ) {
::spdlog::set_default_logger( logger_shptr );
logger_shptr.reset();
}
}

0 comments on commit f6e440c

Please sign in to comment.