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
144 changes: 29 additions & 115 deletions common/base/include/claraparabricks/genomeworks/logging/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,63 +42,9 @@
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

#include <claraparabricks/genomeworks/gw_config.hpp>

/// \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,88 +53,56 @@ 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
};

/// \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 initialize_logger(LogLevel level, const char* filename = nullptr);

/// 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 char* file, int line, const char* msg);
} // namespace logging

/// \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);
} // namespace genomeworks

} // namespace claraparabricks

/// \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)

/// \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

} // namespace logging

} // namespace genomeworks

} // namespace claraparabricks

/// \brief Log at fatal/critical error level
#define GW_LOG_CRITICAL(msg) claraparabricks::genomeworks::logging::log(claraparabricks::genomeworks::logging::LogLevel::critical, __FILE__, __LINE__, msg)
/// \}
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("Trying to allocate memory from an default-constructed CachingDeviceAllocator. Please assign a non-default-constructed CachingDeviceAllocator before performing any memory operations.");
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("Trying to deallocate memory from an default-constructed CachingDeviceAllocator. Please assign a non-default-constructed CachingDeviceAllocator before performing any memory operations.");
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
97 changes: 50 additions & 47 deletions common/base/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#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>
#include <cassert>

namespace claraparabricks
{
Expand All @@ -27,66 +29,67 @@ namespace genomeworks

namespace logging
{
static std::shared_ptr<spdlog::logger> logger = nullptr;
static std::unique_ptr<std::ostream> out_stream_ = nullptr;

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;
initialize_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;
default:
assert(false); // Unknown log level
prefix = "INFO";
break;
}
return prefix;
}

if (filename != nullptr)
void initialize_logger(LogLevel level, const char* filename)
{
if (out_stream_ == nullptr)
{
try
level_ = level;
if (filename != nullptr)
{
logger = spdlog::basic_logger_mt("GWLogger", filename);
out_stream_ = std::make_unique<std::ofstream>(filename);
}
catch (const spdlog::spdlog_ex& ex)
else
{
return LoggingStatus::cannot_open_file;
out_stream_ = std::make_unique<std::ostream>(std::cerr.rdbuf());
}
assert(out_stream_->good());
ahehn-nv marked this conversation as resolved.
Show resolved Hide resolved
*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)
{
return LoggingStatus::cannot_open_stdout;
}
*out_stream_ << "Logger already initialized with log level " << log_level_str(level_) << std::endl;
}

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)
void log(LogLevel level, const char* file, int32_t line, const char* msg)
{
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;
check_logger();
if (level <= level_)
{
*out_stream_ << "[" << log_level_str(level) << " " << file << ":" << line << "] " << msg << std::endl;
}
}

} // namespace logging

} // namespace genomeworks
Expand Down
Loading