mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 21:40:33 +05:00
Merge branch 'remove_archive_logging' into 'master'
remove spdlog and archive logging See merge request ngsolve/netgen!592
This commit is contained in:
commit
359d7d3da9
@ -185,13 +185,6 @@ test_build_ngsolve:
|
|||||||
# when: always
|
# when: always
|
||||||
# allow_failure: true
|
# allow_failure: true
|
||||||
|
|
||||||
# check if it compiles without spdlog
|
|
||||||
test_noSpdlog:
|
|
||||||
<<: *ubuntu
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- docker run -e CCACHE_DIR=/ccache -v /mnt/ccache:/ccache netgen_${CI_PIPELINE_ID}:${UBUNTU_VERSION} bash /root/src/netgen/tests/build_nospdlog.sh
|
|
||||||
|
|
||||||
cleanup_ubuntu:
|
cleanup_ubuntu:
|
||||||
stage: cleanup
|
stage: cleanup
|
||||||
tags:
|
tags:
|
||||||
|
@ -32,7 +32,6 @@ option( USE_CCACHE "use ccache")
|
|||||||
option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" ON)
|
option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" ON)
|
||||||
option( ENABLE_UNIT_TESTS "Enable Catch unit tests")
|
option( ENABLE_UNIT_TESTS "Enable Catch unit tests")
|
||||||
option( ENABLE_CPP_CORE_GUIDELINES_CHECK "Enable cpp core guideline checks on ngcore" OFF)
|
option( ENABLE_CPP_CORE_GUIDELINES_CHECK "Enable cpp core guideline checks on ngcore" OFF)
|
||||||
option( USE_SPDLOG "Enable spd log logging" OFF)
|
|
||||||
option( DEBUG_LOG "Enable more debug output (may increase computation time) - only works with USE_SPDLOG=ON" OFF)
|
option( DEBUG_LOG "Enable more debug output (may increase computation time) - only works with USE_SPDLOG=ON" OFF)
|
||||||
option( CHECK_RANGE "Check array range access, automatically enabled if built in debug mode" OFF)
|
option( CHECK_RANGE "Check array range access, automatically enabled if built in debug mode" OFF)
|
||||||
option( BUILD_STUB_FILES "Build stub files for better autocompletion" ON)
|
option( BUILD_STUB_FILES "Build stub files for better autocompletion" ON)
|
||||||
|
@ -55,19 +55,6 @@ if(TRACE_MEMORY)
|
|||||||
target_compile_definitions(ngcore PUBLIC NETGEN_TRACE_MEMORY)
|
target_compile_definitions(ngcore PUBLIC NETGEN_TRACE_MEMORY)
|
||||||
endif(TRACE_MEMORY)
|
endif(TRACE_MEMORY)
|
||||||
|
|
||||||
|
|
||||||
if(USE_SPDLOG)
|
|
||||||
include_directories(${SPDLOG_INCLUDE_DIR})
|
|
||||||
install(DIRECTORY ${SPDLOG_INCLUDE_DIR}
|
|
||||||
DESTINATION ${NG_INSTALL_DIR_INCLUDE}
|
|
||||||
)
|
|
||||||
add_dependencies(ngcore project_spdlog)
|
|
||||||
target_compile_definitions(ngcore PUBLIC NETGEN_USE_SPDLOG)
|
|
||||||
if(DEBUG_LOG)
|
|
||||||
target_compile_definitions(ngcore PUBLIC NETGEN_LOG_DEBUG)
|
|
||||||
endif(DEBUG_LOG)
|
|
||||||
endif(USE_SPDLOG)
|
|
||||||
|
|
||||||
if(USE_NUMA)
|
if(USE_NUMA)
|
||||||
find_library(NUMA_LIBRARY libnuma.so)
|
find_library(NUMA_LIBRARY libnuma.so)
|
||||||
target_compile_definitions(ngcore PUBLIC USE_NUMA)
|
target_compile_definitions(ngcore PUBLIC USE_NUMA)
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
#include "exception.hpp" // for UnreachableCodeException, Exception
|
#include "exception.hpp" // for UnreachableCodeException, Exception
|
||||||
#include "logging.hpp" // for logger
|
|
||||||
#include "ngcore_api.hpp" // for NGCORE_API
|
#include "ngcore_api.hpp" // for NGCORE_API
|
||||||
#include "type_traits.hpp" // for all_of_tmpl
|
#include "type_traits.hpp" // for all_of_tmpl
|
||||||
#include "utils.hpp" // for Demangle, unlikely
|
#include "utils.hpp" // for Demangle, unlikely
|
||||||
@ -133,7 +132,6 @@ namespace ngcore
|
|||||||
protected:
|
protected:
|
||||||
bool shallow_to_python = false;
|
bool shallow_to_python = false;
|
||||||
std::map<std::string, VersionInfo> version_map = GetLibraryVersions();
|
std::map<std::string, VersionInfo> version_map = GetLibraryVersions();
|
||||||
std::shared_ptr<Logger> logger = GetLogger("Archive");
|
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr bool is_archivable = detail::is_Archivable_struct<T>::value;
|
static constexpr bool is_archivable = detail::is_Archivable_struct<T>::value;
|
||||||
@ -254,7 +252,6 @@ namespace ngcore
|
|||||||
// don't use it that often anyway)
|
// don't use it that often anyway)
|
||||||
Archive& operator& (std::vector<bool>& v)
|
Archive& operator& (std::vector<bool>& v)
|
||||||
{
|
{
|
||||||
logger->debug("In special archive for std::vector<bool>");
|
|
||||||
size_t size;
|
size_t size;
|
||||||
if(Output())
|
if(Output())
|
||||||
size = v.size();
|
size = v.size();
|
||||||
@ -409,22 +406,15 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
if(Output())
|
if(Output())
|
||||||
{
|
{
|
||||||
logger->debug("Store shared ptr of type {}", Demangle(typeid(T).name()));
|
|
||||||
// save -2 for nullptr
|
// save -2 for nullptr
|
||||||
if(!ptr)
|
if(!ptr)
|
||||||
{
|
return (*this) << -2;
|
||||||
logger->debug("Storing nullptr");
|
|
||||||
return (*this) << -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* reg_ptr = ptr.get();
|
void* reg_ptr = ptr.get();
|
||||||
bool neededDowncast = false;
|
bool neededDowncast = false;
|
||||||
// Downcasting is only possible for our registered classes
|
// Downcasting is only possible for our registered classes
|
||||||
if(typeid(T) != typeid(*ptr))
|
if(typeid(T) != typeid(*ptr))
|
||||||
{
|
{
|
||||||
logger->debug("Typids are different: {} vs {}",
|
|
||||||
Demangle(typeid(T).name()),
|
|
||||||
Demangle(typeid(*ptr).name()));
|
|
||||||
if(!IsRegistered(Demangle(typeid(*ptr).name())))
|
if(!IsRegistered(Demangle(typeid(*ptr).name())))
|
||||||
throw Exception(std::string("Archive error: Polymorphic type ")
|
throw Exception(std::string("Archive error: Polymorphic type ")
|
||||||
+ Demangle(typeid(*ptr).name())
|
+ Demangle(typeid(*ptr).name())
|
||||||
@ -432,17 +422,12 @@ namespace ngcore
|
|||||||
reg_ptr = GetArchiveRegister(Demangle(typeid(*ptr).name())).downcaster(typeid(T), ptr.get());
|
reg_ptr = GetArchiveRegister(Demangle(typeid(*ptr).name())).downcaster(typeid(T), ptr.get());
|
||||||
// if there was a true downcast we have to store more information
|
// if there was a true downcast we have to store more information
|
||||||
if(reg_ptr != static_cast<void*>(ptr.get()))
|
if(reg_ptr != static_cast<void*>(ptr.get()))
|
||||||
{
|
neededDowncast = true;
|
||||||
logger->debug("Multiple/Virtual inheritance involved, need to cast pointer");
|
|
||||||
neededDowncast = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
auto pos = shared_ptr2nr.find(reg_ptr);
|
auto pos = shared_ptr2nr.find(reg_ptr);
|
||||||
// if not found store -1 and the pointer
|
// if not found store -1 and the pointer
|
||||||
if(pos == shared_ptr2nr.end())
|
if(pos == shared_ptr2nr.end())
|
||||||
{
|
{
|
||||||
logger->debug("Didn't find the shared_ptr, create new registry entry at {}",
|
|
||||||
shared_ptr_count);
|
|
||||||
auto p = ptr.get();
|
auto p = ptr.get();
|
||||||
(*this) << -1;
|
(*this) << -1;
|
||||||
(*this) & neededDowncast & p;
|
(*this) & neededDowncast & p;
|
||||||
@ -453,27 +438,23 @@ namespace ngcore
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
// if found store the position and if it has to be downcasted and how
|
// if found store the position and if it has to be downcasted and how
|
||||||
logger->debug("Found shared_ptr at position {}", pos->second);
|
|
||||||
(*this) << pos->second << neededDowncast;
|
(*this) << pos->second << neededDowncast;
|
||||||
if(neededDowncast)
|
if(neededDowncast)
|
||||||
(*this) << Demangle(typeid(*ptr).name());
|
(*this) << Demangle(typeid(*ptr).name());
|
||||||
}
|
}
|
||||||
else // Input
|
else // Input
|
||||||
{
|
{
|
||||||
logger->debug("Reading shared_ptr of type {}", Demangle(typeid(T).name()));
|
|
||||||
int nr;
|
int nr;
|
||||||
(*this) & nr;
|
(*this) & nr;
|
||||||
// -2 restores a nullptr
|
// -2 restores a nullptr
|
||||||
if(nr == -2)
|
if(nr == -2)
|
||||||
{
|
{
|
||||||
logger->debug("Reading a nullptr");
|
|
||||||
ptr = nullptr;
|
ptr = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
// -1 restores a new shared ptr by restoring the inner pointer and creating a shared_ptr to it
|
// -1 restores a new shared ptr by restoring the inner pointer and creating a shared_ptr to it
|
||||||
if (nr == -1)
|
if (nr == -1)
|
||||||
{
|
{
|
||||||
logger->debug("Creating new shared_ptr");
|
|
||||||
T* p = nullptr;
|
T* p = nullptr;
|
||||||
bool neededDowncast;
|
bool neededDowncast;
|
||||||
(*this) & neededDowncast & p;
|
(*this) & neededDowncast & p;
|
||||||
@ -481,7 +462,6 @@ namespace ngcore
|
|||||||
// if we did downcast we need to store a shared_ptr<void> to the true object
|
// if we did downcast we need to store a shared_ptr<void> to the true object
|
||||||
if(neededDowncast)
|
if(neededDowncast)
|
||||||
{
|
{
|
||||||
logger->debug("Shared pointer needed downcasting");
|
|
||||||
std::string name;
|
std::string name;
|
||||||
(*this) & name;
|
(*this) & name;
|
||||||
auto info = GetArchiveRegister(name);
|
auto info = GetArchiveRegister(name);
|
||||||
@ -492,20 +472,15 @@ namespace ngcore
|
|||||||
ptr.get())));
|
ptr.get())));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
logger->debug("Shared pointer didn't need downcasting");
|
|
||||||
nr2shared_ptr.push_back(ptr);
|
nr2shared_ptr.push_back(ptr);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger->debug("Reading already existing pointer at entry {}", nr);
|
|
||||||
auto other = nr2shared_ptr[nr];
|
auto other = nr2shared_ptr[nr];
|
||||||
bool neededDowncast;
|
bool neededDowncast;
|
||||||
(*this) & neededDowncast;
|
(*this) & neededDowncast;
|
||||||
if(neededDowncast)
|
if(neededDowncast)
|
||||||
{
|
{
|
||||||
logger->debug("Shared pointer needed pointer downcast");
|
|
||||||
// if there was a downcast we can expect the class to be registered (since archiving
|
// if there was a downcast we can expect the class to be registered (since archiving
|
||||||
// wouldn't have worked else)
|
// wouldn't have worked else)
|
||||||
std::string name;
|
std::string name;
|
||||||
@ -519,7 +494,6 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger->debug("Shared pointer didn't need pointer casts");
|
|
||||||
ptr = std::static_pointer_cast<T>(other);
|
ptr = std::static_pointer_cast<T>(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -533,42 +507,26 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
if (Output())
|
if (Output())
|
||||||
{
|
{
|
||||||
logger->debug("Store pointer of type {}",Demangle(typeid(T).name()));
|
|
||||||
// if the pointer is null store -2
|
// if the pointer is null store -2
|
||||||
if (!p)
|
if (!p)
|
||||||
{
|
|
||||||
logger->debug("Storing nullptr");
|
|
||||||
return (*this) << -2;
|
return (*this) << -2;
|
||||||
}
|
|
||||||
auto reg_ptr = static_cast<void*>(p);
|
auto reg_ptr = static_cast<void*>(p);
|
||||||
if(typeid(T) != typeid(*p))
|
if(typeid(T) != typeid(*p))
|
||||||
{
|
{
|
||||||
logger->debug("Typeids are different: {} vs {}",
|
|
||||||
Demangle(typeid(T).name()),
|
|
||||||
Demangle(typeid(*p).name()));
|
|
||||||
if(!IsRegistered(Demangle(typeid(*p).name())))
|
if(!IsRegistered(Demangle(typeid(*p).name())))
|
||||||
throw Exception(std::string("Archive error: Polymorphic type ")
|
throw Exception(std::string("Archive error: Polymorphic type ")
|
||||||
+ Demangle(typeid(*p).name())
|
+ Demangle(typeid(*p).name())
|
||||||
+ " not registered for archive");
|
+ " not registered for archive");
|
||||||
reg_ptr = GetArchiveRegister(Demangle(typeid(*p).name())).downcaster(typeid(T), static_cast<void*>(p));
|
reg_ptr = GetArchiveRegister(Demangle(typeid(*p).name())).downcaster(typeid(T), static_cast<void*>(p));
|
||||||
if(reg_ptr != static_cast<void*>(p))
|
|
||||||
{
|
|
||||||
logger->debug("Multiple/Virtual inheritance involved, need to cast pointer");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
auto pos = ptr2nr.find(reg_ptr);
|
auto pos = ptr2nr.find(reg_ptr);
|
||||||
// if the pointer is not found in the map create a new entry
|
// if the pointer is not found in the map create a new entry
|
||||||
if (pos == ptr2nr.end())
|
if (pos == ptr2nr.end())
|
||||||
{
|
{
|
||||||
logger->debug("Didn't find pointer, create new registry entry at {}",
|
|
||||||
ptr_count);
|
|
||||||
ptr2nr[reg_ptr] = ptr_count++;
|
ptr2nr[reg_ptr] = ptr_count++;
|
||||||
if(typeid(*p) == typeid(T))
|
if(typeid(*p) == typeid(T))
|
||||||
if (std::is_constructible<T>::value)
|
if (std::is_constructible<T>::value)
|
||||||
{
|
return (*this) << -1 & (*p);
|
||||||
logger->debug("Store standard class pointer (no virt. inh,...)");
|
|
||||||
return (*this) << -1 & (*p);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
throw Exception(std::string("Archive error: Class ") +
|
throw Exception(std::string("Archive error: Class ") +
|
||||||
Demangle(typeid(*p).name()) + " does not provide a default constructor!");
|
Demangle(typeid(*p).name()) + " does not provide a default constructor!");
|
||||||
@ -582,7 +540,6 @@ namespace ngcore
|
|||||||
throw Exception(std::string("Archive error: Polymorphic type ")
|
throw Exception(std::string("Archive error: Polymorphic type ")
|
||||||
+ Demangle(typeid(*p).name())
|
+ Demangle(typeid(*p).name())
|
||||||
+ " not registered for archive");
|
+ " not registered for archive");
|
||||||
logger->debug("Store a possibly more complicated pointer");
|
|
||||||
return (*this) << -3 << Demangle(typeid(*p).name()) & (*p);
|
return (*this) << -3 << Demangle(typeid(*p).name()) & (*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -590,37 +547,27 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
(*this) & pos->second;
|
(*this) & pos->second;
|
||||||
bool downcasted = !(reg_ptr == static_cast<void*>(p) );
|
bool downcasted = !(reg_ptr == static_cast<void*>(p) );
|
||||||
logger->debug("Store a the existing position in registry at {}", pos->second);
|
|
||||||
logger->debug("Pointer {} downcasting", downcasted ? "needs" : "doesn't need");
|
|
||||||
// store if the class has been downcasted and the name
|
// store if the class has been downcasted and the name
|
||||||
(*this) << downcasted << Demangle(typeid(*p).name());
|
(*this) << downcasted << Demangle(typeid(*p).name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger->debug("Reading pointer of type {}", Demangle(typeid(T).name()));
|
|
||||||
int nr;
|
int nr;
|
||||||
(*this) & nr;
|
(*this) & nr;
|
||||||
if (nr == -2) // restore a nullptr
|
if (nr == -2) // restore a nullptr
|
||||||
{
|
|
||||||
logger->debug("Loading a nullptr");
|
|
||||||
p = nullptr;
|
p = nullptr;
|
||||||
}
|
|
||||||
else if (nr == -1) // create a new pointer of standard type (no virtual or multiple inheritance,...)
|
else if (nr == -1) // create a new pointer of standard type (no virtual or multiple inheritance,...)
|
||||||
{
|
{
|
||||||
logger->debug("Load a new pointer to a simple class");
|
|
||||||
p = detail::constructIfPossible<T>();
|
p = detail::constructIfPossible<T>();
|
||||||
nr2ptr.push_back(p);
|
nr2ptr.push_back(p);
|
||||||
(*this) & *p;
|
(*this) & *p;
|
||||||
}
|
}
|
||||||
else if(nr == -3) // restore one of our registered classes that can have multiple inheritance,...
|
else if(nr == -3) // restore one of our registered classes that can have multiple inheritance,...
|
||||||
{
|
{
|
||||||
logger->debug("Load a new pointer to a potentially more complicated class "
|
|
||||||
"(allows for multiple/virtual inheritance,...)");
|
|
||||||
// As stated above, we want this special behaviour only for our classes that implement DoArchive
|
// As stated above, we want this special behaviour only for our classes that implement DoArchive
|
||||||
std::string name;
|
std::string name;
|
||||||
(*this) & name;
|
(*this) & name;
|
||||||
logger->debug("Name = {}", name);
|
|
||||||
auto info = GetArchiveRegister(name);
|
auto info = GetArchiveRegister(name);
|
||||||
// the creator creates a new object of type name, and returns a void* pointing
|
// the creator creates a new object of type name, and returns a void* pointing
|
||||||
// to T (which may have an offset)
|
// to T (which may have an offset)
|
||||||
@ -632,11 +579,9 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger->debug("Restoring pointer to already existing object at registry position {}", nr);
|
|
||||||
bool downcasted;
|
bool downcasted;
|
||||||
std::string name;
|
std::string name;
|
||||||
(*this) & downcasted & name;
|
(*this) & downcasted & name;
|
||||||
logger->debug("{} object of type {}", downcasted ? "Downcasted" : "Not downcasted", name);
|
|
||||||
if(downcasted)
|
if(downcasted)
|
||||||
{
|
{
|
||||||
// if the class has been downcasted we can assume it is in the register
|
// if the class has been downcasted we can assume it is in the register
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
|
|
||||||
#ifdef NETGEN_USE_SPDLOG
|
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
#include <spdlog/sinks/ansicolor_sink.h>
|
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
|
||||||
|
|
||||||
#else // NETGEN_USE_SPDLOG
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#endif // NETGEN_USE_SPDLOG
|
|
||||||
|
|
||||||
|
|
||||||
namespace ngcore
|
namespace ngcore
|
||||||
{
|
{
|
||||||
@ -19,94 +10,10 @@ namespace ngcore
|
|||||||
|
|
||||||
void Logger::log(level::level_enum level, std::string && s)
|
void Logger::log(level::level_enum level, std::string && s)
|
||||||
{
|
{
|
||||||
#ifdef NETGEN_USE_SPDLOG
|
|
||||||
logger->log(spdlog::level::level_enum(level), s);
|
|
||||||
#else // NETGEN_USE_SPDLOG
|
|
||||||
if(level>=global_level)
|
if(level>=global_level)
|
||||||
std::clog << s << '\n';
|
std::clog << s << '\n';
|
||||||
#endif // NETGEN_USE_SPDLOG
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NETGEN_USE_SPDLOG
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
std::vector<std::shared_ptr<spdlog::sinks::sink>>& GetDefaultSinks()
|
|
||||||
{
|
|
||||||
static std::vector<std::shared_ptr<spdlog::sinks::sink>> sinks =
|
|
||||||
{ std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>() };
|
|
||||||
return sinks;
|
|
||||||
}
|
|
||||||
std::shared_ptr<spdlog::logger> CreateDefaultLogger(const std::string& name)
|
|
||||||
{
|
|
||||||
auto& default_sinks = GetDefaultSinks();
|
|
||||||
auto logger = std::make_shared<spdlog::logger>(name, default_sinks.begin(), default_sinks.end());
|
|
||||||
spdlog::details::registry::instance().register_and_init(logger);
|
|
||||||
return logger;
|
|
||||||
}
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
std::shared_ptr<Logger> GetLogger(const std::string& name)
|
|
||||||
{
|
|
||||||
auto logger = spdlog::get(name);
|
|
||||||
if(!logger)
|
|
||||||
logger = detail::CreateDefaultLogger(name);
|
|
||||||
return std::make_shared<Logger>(logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetLoggingLevel(spdlog::level::level_enum level, const std::string& name)
|
|
||||||
{
|
|
||||||
if(!name.empty())
|
|
||||||
spdlog::get(name)->set_level(level);
|
|
||||||
else
|
|
||||||
spdlog::set_level(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddFileSink(const std::string& filename, spdlog::level::level_enum level, const std::string& logger)
|
|
||||||
{
|
|
||||||
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename);
|
|
||||||
sink->set_level(level);
|
|
||||||
if(!logger.empty())
|
|
||||||
GetLogger(logger)->logger->sinks().push_back(sink);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
detail::GetDefaultSinks().push_back(sink);
|
|
||||||
spdlog::details::registry::instance().apply_all([sink](auto logger) { logger->sinks().push_back(sink); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddConsoleSink(spdlog::level::level_enum level, const std::string& logger)
|
|
||||||
{
|
|
||||||
auto sink = std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>();
|
|
||||||
sink->set_level(level);
|
|
||||||
if(!logger.empty())
|
|
||||||
GetLogger(logger)->logger->sinks().push_back(sink);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
detail::GetDefaultSinks().push_back(sink);
|
|
||||||
spdlog::details::registry::instance().apply_all([sink](auto logger) { logger->sinks().push_back(sink); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClearLoggingSinks(const std::string& logger)
|
|
||||||
{
|
|
||||||
if(!logger.empty())
|
|
||||||
GetLogger(logger)->logger->sinks().clear();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
detail::GetDefaultSinks().clear();
|
|
||||||
spdlog::details::registry::instance().apply_all([](auto logger) { logger->sinks().clear(); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlushOnLoggingLevel(spdlog::level::level_enum level, const std::string& logger)
|
|
||||||
{
|
|
||||||
if(!logger.empty())
|
|
||||||
GetLogger(logger)->logger->flush_on(level);
|
|
||||||
else
|
|
||||||
spdlog::flush_on(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // NETGEN_USE_SPDLOG
|
|
||||||
} //namespace ngcore
|
} //namespace ngcore
|
||||||
|
|
||||||
namespace spdlog
|
namespace spdlog
|
||||||
@ -140,5 +47,3 @@ namespace ngcore
|
|||||||
void ClearLoggingSinks(const std::string& /*unused*/) {}
|
void ClearLoggingSinks(const std::string& /*unused*/) {}
|
||||||
void FlushOnLoggingLevel(level::level_enum /*unused*/, const std::string& /*unused*/) {}
|
void FlushOnLoggingLevel(level::level_enum /*unused*/, const std::string& /*unused*/) {}
|
||||||
} //namespace ngcore
|
} //namespace ngcore
|
||||||
|
|
||||||
#endif // NETGEN_USE_SPDLOG
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef NETGEN_CORE_LOGGING_HPP
|
#ifndef NETGEN_CORE_LOGGING_HPP
|
||||||
#define NETGEN_CORE_LOGGING_HPP
|
#define NETGEN_CORE_LOGGING_HPP
|
||||||
|
|
||||||
#undef NETGEN_USE_SPDLOG
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -11,15 +10,6 @@
|
|||||||
#include "ngcore_api.hpp"
|
#include "ngcore_api.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
#ifdef NETGEN_USE_SPDLOG
|
|
||||||
#include <spdlog/fmt/fmt.h>
|
|
||||||
#include <spdlog/fmt/ostr.h> // to be able to parse anything to logger that implements operator << ostream
|
|
||||||
#ifdef NETGEN_LOG_DEBUG
|
|
||||||
#define SPDLOG_DEBUG_ON
|
|
||||||
#define NETGEN_DEBUG_LOG(logger, ...) SPDLOG_DEBUG(logger, __VA_ARGS__)
|
|
||||||
#endif // NETGEN_LOG_DEBUG
|
|
||||||
#endif // NETGEN_USE_SPDLOG
|
|
||||||
|
|
||||||
#ifndef NETGEN_DEBUG_LOG
|
#ifndef NETGEN_DEBUG_LOG
|
||||||
#define NETGEN_DEBUG_LOG(logger, ...)
|
#define NETGEN_DEBUG_LOG(logger, ...)
|
||||||
#endif // NETGEN_DEBUG_LOG
|
#endif // NETGEN_DEBUG_LOG
|
||||||
@ -60,13 +50,6 @@ namespace ngcore
|
|||||||
|
|
||||||
void NGCORE_API log( level::level_enum level, std::string && s);
|
void NGCORE_API log( level::level_enum level, std::string && s);
|
||||||
|
|
||||||
#ifdef NETGEN_USE_SPDLOG
|
|
||||||
template<typename ... Args>
|
|
||||||
void log( level::level_enum level, const char* str, Args ... args)
|
|
||||||
{
|
|
||||||
log(level, fmt::format(str, args...));
|
|
||||||
}
|
|
||||||
#else // NETGEN_USE_SPDLOG
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string replace(std::string s, const T & t)
|
std::string replace(std::string s, const T & t)
|
||||||
{
|
{
|
||||||
@ -100,7 +83,6 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
log(level, log_helper(std::string(str), args...));
|
log(level, log_helper(std::string(str), args...));
|
||||||
}
|
}
|
||||||
#endif // NETGEN_USE_SPDLOG
|
|
||||||
|
|
||||||
template<typename ... Args>
|
template<typename ... Args>
|
||||||
void trace( const char* str, Args ... args) { log(level::level_enum::trace, str, args...); }
|
void trace( const char* str, Args ... args) { log(level::level_enum::trace, str, args...); }
|
||||||
|
@ -190,7 +190,6 @@ namespace ngcore
|
|||||||
protected:
|
protected:
|
||||||
using ARCHIVE::stream;
|
using ARCHIVE::stream;
|
||||||
using ARCHIVE::version_map;
|
using ARCHIVE::version_map;
|
||||||
using ARCHIVE::logger;
|
|
||||||
public:
|
public:
|
||||||
PyArchive(const pybind11::object& alst = pybind11::none()) :
|
PyArchive(const pybind11::object& alst = pybind11::none()) :
|
||||||
ARCHIVE(std::make_shared<std::stringstream>()),
|
ARCHIVE(std::make_shared<std::stringstream>()),
|
||||||
@ -202,7 +201,6 @@ namespace ngcore
|
|||||||
stream = std::make_shared<std::stringstream>
|
stream = std::make_shared<std::stringstream>
|
||||||
(pybind11::cast<pybind11::bytes>(lst[pybind11::len(lst)-1]));
|
(pybind11::cast<pybind11::bytes>(lst[pybind11::len(lst)-1]));
|
||||||
*this & version_needed;
|
*this & version_needed;
|
||||||
logger->debug("versions needed for unpickling = {}", version_needed);
|
|
||||||
for(auto& libversion : version_needed)
|
for(auto& libversion : version_needed)
|
||||||
if(libversion.second > GetLibraryVersion(libversion.first))
|
if(libversion.second > GetLibraryVersion(libversion.first))
|
||||||
throw Exception("Error in unpickling data:\nLibrary " + libversion.first +
|
throw Exception("Error in unpickling data:\nLibrary " + libversion.first +
|
||||||
@ -219,7 +217,6 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
if(Output())
|
if(Output())
|
||||||
{
|
{
|
||||||
logger->debug("Need version {} of library {}.", version, library);
|
|
||||||
version_needed[library] = version_needed[library] > version ? version_needed[library] : version;
|
version_needed[library] = version_needed[library] > version ? version_needed[library] : version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,7 +240,6 @@ namespace ngcore
|
|||||||
FlushBuffer();
|
FlushBuffer();
|
||||||
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
||||||
stream = std::make_shared<std::stringstream>();
|
stream = std::make_shared<std::stringstream>();
|
||||||
logger->debug("Writeout version needed = {}", version_needed);
|
|
||||||
*this & version_needed;
|
*this & version_needed;
|
||||||
FlushBuffer();
|
FlushBuffer();
|
||||||
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
lst.append(pybind11::bytes(std::static_pointer_cast<std::stringstream>(stream)->str()));
|
||||||
|
Loading…
Reference in New Issue
Block a user