// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/fmt/bin_to_hex.h" #include "Logger.h" #include "GitInfo.h" Logger::Logger(const std::string &service_name, const std::string &file_name) { std::string variant = ""; #ifdef JFJOCH_USE_CUDA variant += "C"; #endif #ifdef JFJOCH_USE_FFTW variant += "F"; #endif std::vector sinks; sinks.push_back(std::make_shared()); if (!file_name.empty()) sinks.push_back(std::make_shared(file_name, 23, 59)); spdlog_logger = std::make_shared(service_name, std::begin(sinks), std::end(sinks)); if (jfjoch_git_sha1().empty()) spdlog_logger->info("Version {} {}", jfjoch_version(), variant); else spdlog_logger->info("Version {} (git {} {}) {}", jfjoch_version(), jfjoch_git_sha1().substr(0, 6), jfjoch_git_date(), variant); } void Logger::ErrorException(const std::exception &e) { spdlog_logger->error(e.what()); } Logger &Logger::Verbose(bool input) { if (input) spdlog_logger->set_level(spdlog::level::debug); else spdlog_logger->set_level(spdlog::level::info); return *this; }