Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[logging] remove spdlog submodule which resolves many issues #615

Merged
Merged
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
[submodule "3rdparty/googletest"]
path = 3rdparty/googletest
url = https://github.com/google/googletest.git
[submodule "3rdparty/spdlog"]
path = 3rdparty/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "3rdparty/benchmark"]
path = 3rdparty/benchmark
url = https://github.com/google/benchmark.git
Expand Down
1 change: 0 additions & 1 deletion 3rdparty/spdlog
Submodule spdlog deleted from 366935
6 changes: 0 additions & 6 deletions cmake/3rdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ if (enable_benchmarks AND NOT TARGET benchmark)
add_subdirectory(3rdparty/benchmark EXCLUDE_FROM_ALL)
endif()

if (NOT TARGET spdlog)
# FORCE spdlog to put out an install target, which we need
set(SPDLOG_INSTALL ON CACHE BOOL "Generate the install target." FORCE)
add_subdirectory(3rdparty/spdlog EXCLUDE_FROM_ALL)
endif()

if (NOT TARGET spoa)
add_subdirectory(3rdparty/spoa EXCLUDE_FROM_ALL)
# Don't show warnings when compiling the 3rd party library
Expand Down
4 changes: 1 addition & 3 deletions common/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

set(MODULE_NAME gwbase)

find_package(CUDA 9.0 QUIET REQUIRED)

set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++14")
message(STATUS "nvcc flags for ${MODULE_NAME}: ${CUDA_NVCC_FLAGS}")

Expand All @@ -29,7 +27,7 @@ add_library(${MODULE_NAME} ${gw_library_type}
src/logging.cpp
src/graph.cpp
)
target_link_libraries(${MODULE_NAME} PUBLIC spdlog ${CUDA_LIBRARIES})
target_link_libraries(${MODULE_NAME} PUBLIC ${CUDA_LIBRARIES})

if (gw_profiling)
find_library(NVTX_LIBRARY nvToolsExt HINTS ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
Expand Down
122 changes: 26 additions & 96 deletions common/base/include/claraparabricks/genomeworks/logging/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,12 @@

#include <claraparabricks/genomeworks/gw_config.hpp>

#include <cstdint>
#include <string>

/// \ingroup logging
/// \{

/// \brief DEBUG log level
#define gw_log_level_debug 0
/// \brief INFO log level
#define gw_log_level_info 1
/// \brief WARN log level
#define gw_log_level_warn 2
/// \brief ERROR log level
#define gw_log_level_error 3
/// \brief CRITICAL log level
#define gw_log_level_critical 4
/// \brief No logging
#define gw_log_level_off 5

#ifndef GW_LOG_LEVEL
#ifndef NDEBUG
/// \brief Defines the logging level used in the current module
#define GW_LOG_LEVEL gw_log_level_debug
#else // NDEBUG
/// \brief Defines the logging level used in the current module
#define GW_LOG_LEVEL gw_log_level_error
#endif // NDEBUG
#endif // GW_LOG_LEVEL

#if GW_LOG_LEVEL == gw_log_level_info
/// \brief Set log level to INFO
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
#elif GW_LOG_LEVEL == gw_log_level_debug
/// \brief Set log level to DEBUG
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_DEBUG
#elif GW_LOG_LEVEL == gw_log_level_warn
/// \brief Set log level to WARN
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_WARN
#elif GW_LOG_LEVEL == gw_log_level_error
/// \brief Set log level to ERROR
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_ERROR
#elif GW_LOG_LEVEL == gw_log_level_critical
/// \brief Set log level to CRITICAL
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_CRITICAL
#else
/// \brief Set log level to OFF
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_OFF
#endif

// MUST come after the defines of the logging level!
#if __GNUC__ >= 9
// Due to a ISO C++ standard incompatibility the spdlog fails to pass
// pedantic requirements.
#pragma message("Logging disabled for GCC >= 9")
#else
#include <spdlog/spdlog.h>
#endif

namespace claraparabricks
{

Expand All @@ -107,84 +58,63 @@ namespace genomeworks

namespace logging
{
/// \ingroup logging
/// Logging status type
enum class LoggingStatus

/// GenomeWorks Logging levels.
enum LogLevel
{
success = 0, ///< Success
cannot_open_file, ///< Initialization could not open the output file requested
cannot_open_stdout ///< Stdout could not be opened for logging
CRITICAL = 0,
ERROR,
WARN,
INFO,
DEBUG
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
};

/// \ingroup logging
/// Init Initialize the logging
/// \param filename if specified, the path/name of the file into which logging should be placed.
/// The default is stdout
/// \return success or error status
LoggingStatus Init(const char* filename = nullptr);
/// Initialize logger across GenomeWorks.
/// \param [in] level LogLevel for logger.
/// \param [in] filename File to redirect log messages to.
void create_logger(LogLevel level, const std::string& filename = "");
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved

/// \ingroup logging
/// SetHeader Adjust the header/preface for each log message
/// \param logTime if true, the detailed time will be prepended to each message.
/// \param logLocation if true, the file and line location logging will be prepended to each message.
/// \return success or error status
LoggingStatus SetHeader(bool logTime, bool logLocation);
/// Log messages to logger.
/// \param [in] level LogLevel for message.
/// \param [in] file Filename for originating message.
/// \param [in] line Line number for originating message.
/// \param [in] msg Content of log message.
void log(LogLevel level, const std::string& file, int32_t line, const std::string& msg);
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved

/// \ingroup logging
/// \def GW_LOG_DEBUG
/// \brief Log at debug level
///
/// parameters as per https://github.com/gabime/spdlog/blob/v1.x/README.md
#if __GNUC__ >= 9
#define GW_LOG_DEBUG(...)
#else
#define GW_LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__)
#endif
#define GW_LOG_DEBUG(msg) claraparabricks::genomeworks::logging::log(claraparabricks::genomeworks::logging::LogLevel::DEBUG, __FILE__, __LINE__, msg)
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved

/// \ingroup logging
/// \def GW_LOG_INFO
/// \brief Log at info level
///
/// parameters as per https://github.com/gabime/spdlog/blob/v1.x/README.md
#if __GNUC__ >= 9
#define GW_LOG_INFO(...)
#else
#define GW_LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__)
#endif
#define GW_LOG_INFO(msg) claraparabricks::genomeworks::logging::log(claraparabricks::genomeworks::logging::LogLevel::INFO, __FILE__, __LINE__, msg)

/// \ingroup logging
/// \def GW_LOG_WARN
/// \brief Log at warning level
///
/// parameters as per https://github.com/gabime/spdlog/blob/v1.x/README.md
#if __GNUC__ >= 9
#define GW_LOG_WARN(...)
#else
#define GW_LOG_WARN(...) SPDLOG_WARN(__VA_ARGS__)
#endif
#define GW_LOG_WARN(msg) claraparabricks::genomeworks::logging::log(claraparabricks::genomeworks::logging::LogLevel::WARN, __FILE__, __LINE__, msg)

/// \ingroup logging
/// \def GW_LOG_ERROR
/// \brief Log at error level
///
/// parameters as per https://github.com/gabime/spdlog/blob/v1.x/README.md
#if __GNUC__ >= 9
#define GW_LOG_ERROR(...)
#else
#define GW_LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__)
#endif
#define GW_LOG_ERROR(msg) claraparabricks::genomeworks::logging::log(claraparabricks::genomeworks::logging::LogLevel::ERROR, __FILE__, __LINE__, msg)

/// \ingroup logging
/// \def GW_LOG_CRITICAL
/// \brief Log at fatal/critical error level (does NOT exit)
///
/// parameters as per https://github.com/gabime/spdlog/blob/v1.x/README.md
#if __GNUC__ >= 9
#define GW_LOG_CRITICAL(...)
#else
#define GW_LOG_CRITICAL(...) SPDLOG_CRITICAL(__VA_ARGS__)
#endif

#define GW_LOG_CRITICAL(msg) claraparabricks::genomeworks::logging::log(claraparabricks::genomeworks::logging::LogLevel::CRITICAL, __FILE__, __LINE__, msg)
} // namespace logging

} // namespace genomeworks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class CachingDeviceAllocator
{
if (!memory_resource_)
{
GW_LOG_ERROR("{}\n", "ERROR:: Trying to allocate memory from an default-constructed CachingDeviceAllocator. Please assign a non-default-constructed CachingDeviceAllocator before performing any memory operations.");
GW_LOG_ERROR("ERROR:: Trying to allocate memory from an default-constructed CachingDeviceAllocator. Please assign a non-default-constructed CachingDeviceAllocator before performing any memory operations.");
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
assert(false);
std::abort();
}
Expand All @@ -291,7 +291,7 @@ class CachingDeviceAllocator
static_cast<void>(n);
if (!memory_resource_)
{
GW_LOG_ERROR("{}\n", "ERROR:: Trying to deallocate memory from an default-constructed CachingDeviceAllocator. Please assign a non-default-constructed CachingDeviceAllocator before performing any memory operations.");
GW_LOG_ERROR("ERROR:: Trying to deallocate memory from an default-constructed CachingDeviceAllocator. Please assign a non-default-constructed CachingDeviceAllocator before performing any memory operations.");
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
assert(false);
std::abort();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ inline void gpu_assert(cudaError_t code, const char* file, int line)
std::string(cudaGetErrorString(code)) +
" " + std::string(file) +
" " + std::to_string(line);
GW_LOG_ERROR("{}\n", err);
GW_LOG_ERROR(err.c_str());
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
// In Debug mode, this assert will cause a debugger trap
// which is beneficial when debugging errors.
assert(false);
Expand Down
99 changes: 53 additions & 46 deletions common/base/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

#include <claraparabricks/genomeworks/logging/logging.hpp>

#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_sinks.h>
#include <iostream>
#include <fstream>
#include <memory>

namespace claraparabricks
{
Expand All @@ -27,66 +28,72 @@ namespace genomeworks

namespace logging
{
static std::shared_ptr<spdlog::logger> logger = nullptr;
static std::unique_ptr<std::ostream> out_stream_ = nullptr;
static std::unique_ptr<std::ofstream> out_file_ = nullptr;
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved

LoggingStatus Init(const char* filename)
static LogLevel level_ = LogLevel::ERROR;

void check_logger()
{
// for now, first call wins:
if (logger != nullptr)
return LoggingStatus::success;
if (out_stream_ == nullptr)
{
std::cerr << "GenomeWorks logger not initialized yet. Initializing default logger now." << std::endl;
create_logger(LogLevel::ERROR);
}
}

std::string log_level_str(LogLevel level)
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
{
std::string prefix;
switch (level)
{
case CRITICAL: prefix = "CRITICAL"; break;
case ERROR: prefix = "ERROR"; break;
case WARN: prefix = "WARN"; break;
case INFO: prefix = "INFO"; break;
case DEBUG: prefix = "DEBUG"; break;
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
default: throw std::runtime_error("Unknown Log Level passed.\n");
}
return prefix;
}

if (filename != nullptr)
void create_logger(LogLevel level, const std::string& filename)
{
if (out_stream_ == nullptr)
{
try
std::streambuf* buffer = nullptr;
level_ = level;
if (filename != "")
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
{
logger = spdlog::basic_logger_mt("GWLogger", filename);
out_file_ = std::make_unique<std::ofstream>(filename);
buffer = out_file_->rdbuf();
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
}
catch (const spdlog::spdlog_ex& ex)
else
{
return LoggingStatus::cannot_open_file;
buffer = std::cerr.rdbuf();
}
out_stream_ = std::make_unique<std::ostream>(buffer);
*out_stream_ << "Initialized GenomeWorks logger with log level " << log_level_str(level_) << std::endl;
}
else
{
try
{
logger = spdlog::stderr_logger_mt("GWLogger");
}
catch (const spdlog::spdlog_ex& ex)
*out_stream_ << "Logger already initialized with log level " << log_level_str(level_) << std::endl;
}
}
void log(LogLevel level, const std::string& file, int32_t line, const std::string& msg)
{
check_logger();
if (level <= level_)
{
std::string prefix = log_level_str(level);
*out_stream_ << "[" << prefix << " " << file << ":" << line << "] " << msg << std::endl;
if (level == LogLevel::CRITICAL)
{
return LoggingStatus::cannot_open_stdout;
std::exit(1);
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
}
}

spdlog::set_default_logger(logger);

#ifdef _DEBUG
SetHeader(true, true);
#else
SetHeader(false, false);
#endif

spdlog::flush_every(std::chrono::seconds(1));

return LoggingStatus::success;
}

LoggingStatus SetHeader(bool logTime, bool logLocation)
{
std::string pattern = "";

if (logTime)
pattern = pattern + "[%H:%M:%S %z]";

if (logLocation)
pattern = pattern + "[%@]";

pattern = pattern + "%v";

spdlog::set_pattern(pattern);

return LoggingStatus::success;
}
} // namespace logging

} // namespace genomeworks
Expand Down
Loading