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

BRAYNS-630 Remove spdlog and use fmt. #1252

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ option(BRAYNS_ENABLE_ATLAS "Build atlas support" ON)
option(BRAYNS_ENABLE_APPS "Build applications" ON)
option(BRAYNS_ENABLE_TESTS "Build unit tests" ON)

find_package(fmt REQUIRED)
find_package(OpenMP REQUIRED)
find_package(ospray REQUIRED)
find_package(rkcommon REQUIRED)
find_package(Poco REQUIRED COMPONENTS Foundation JSON Net NetSSL)
find_package(rkcommon REQUIRED)
find_package(ZLIB REQUIRED)
find_package(spdlog REQUIRED)

if(BRAYNS_ENABLE_CIRCUITS)
find_package(HDF5 REQUIRED)
find_package(HighFive REQUIRED)
find_package(sonata REQUIRED)
find_package(MorphIO REQUIRED)
find_package(sonata REQUIRED)
endif()

if(BRAYNS_ENABLE_ATLAS)
Expand Down
24 changes: 12 additions & 12 deletions scripts/superbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ option(BRAYNS_ENABLE_INSTALL "Install Brayns with dependencies" OFF)

include(ExternalProject)

ExternalProject_Add(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.2.1
GIT_SHALLOW ON
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
)

ExternalProject_Add(
libsonata
GIT_REPOSITORY https://github.com/BlueBrain/libsonata.git
Expand Down Expand Up @@ -89,17 +100,6 @@ ExternalProject_Add(
-DENABLE_ACTIVERECORD_COMPILER=OFF
)

ExternalProject_Add(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.13.0
GIT_SHALLOW ON
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
)

if(BRAYNS_ENABLE_INSTALL)
ExternalProject_Add(
Brayns
Expand All @@ -113,10 +113,10 @@ if(BRAYNS_ENABLE_INSTALL)
ExternalProject_Add_StepDependencies(
Brayns
configure
fmt
libsonata
morphio
ospray
poco
spdlog
)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <brayns/core/utils/string/StringSplitter.h>
#include <brayns/core/utils/string/StringTrimmer.h>

#include <spdlog/fmt/bundled/printf.h>
#include <fmt/printf.h>

namespace
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include <algorithm>

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

namespace
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/circuits/api/neuron/NeuronMorphologyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "NeuronMorphologyReader.h"

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

#include <morphio/morphology.h>
#include <morphio/section.h>
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/circuits/io/CellPlacementLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <brayns/core/utils/Log.h>
#include <brayns/core/utils/Timer.h>

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

#include <array>
#include <filesystem>
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/circuits/io/sonataloader/ParameterCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <brayns/circuits/io/sonataloader/data/Names.h>
#include <brayns/circuits/io/sonataloader/data/PopulationType.h>

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

#include <filesystem>
#include <unordered_set>
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/circuits/io/sonataloader/data/detail/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "Common.h"

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

namespace sonataloader::detail
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ set_target_properties(core PROPERTIES OUTPUT_NAME braynsCore)
target_link_libraries(
core
PUBLIC
fmt::fmt
OpenMP::OpenMP_CXX
ospray::ospray
Poco::Foundation
Poco::JSON
Poco::Net
Poco::NetSSL
rkcommon::rkcommon
spdlog::spdlog
PRIVATE
${ZLIB_LIBRARIES}
stb
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "Version.h"

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

namespace brayns
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/engine/colormethods/SolidColorMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <brayns/core/engine/components/ColorSolid.h>
#include <brayns/core/engine/components/GeometryViews.h>

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

namespace
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/engine/systems/GenericColorSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <algorithm>
#include <unordered_set>

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

namespace
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/json/JsonError.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <variant>
#include <vector>

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

namespace brayns
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/json/JsonType.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <type_traits>
#include <unordered_map>

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

#include <Poco/JSON/Array.h>
#include <Poco/JSON/JSONException.h>
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/client/ClientRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <functional>
#include <memory>

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

#include <brayns/core/network/websocket/IWebSocket.h>

Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/client/ClientRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

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

#include <brayns/core/network/websocket/InputPacket.h>

Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/entrypoint/EntrypointRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <stdexcept>

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

namespace brayns
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/jsonrpc/JsonRpcException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "JsonRpcException.h"

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

namespace
{
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/jsonrpc/JsonRpcException.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <stdexcept>

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

#include <brayns/core/json/Json.h>

Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/jsonrpc/JsonRpcParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "JsonRpcParser.h"

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

#include <brayns/core/json/Json.h>

Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/jsonrpc/JsonRpcRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <string_view>

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

#include <brayns/core/network/client/ClientRef.h>
#include <brayns/core/network/jsonrpc/JsonRpcException.h>
Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/jsonrpc/RequestId.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <functional>
#include <typeindex>

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

#include <brayns/core/json/JsonAdapter.h>

Expand Down
2 changes: 1 addition & 1 deletion src/brayns/core/network/task/JsonRpcTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <cassert>

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

#include <brayns/core/utils/Log.h>

Expand Down
30 changes: 8 additions & 22 deletions src/brayns/core/utils/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,7 @@

#include "Log.h"

#include <spdlog/sinks/stdout_color_sinks.h>

namespace
{
class LoggerFactory
{
public:
static std::shared_ptr<spdlog::logger> createLogger()
{
auto logger = spdlog::stdout_color_mt("Brayns");
logger->set_pattern("%^[%l][%T] %v%$");
#ifdef NDEBUG
logger->set_level(spdlog::level::info);
#else
logger->set_level(spdlog::level::debug);
#endif
return logger;
}
};
} // namespace
#include <iostream>

namespace brayns
{
Expand All @@ -60,13 +41,18 @@ EnumMap<LogLevel> EnumReflector<LogLevel>::reflect()

void Log::setLevel(LogLevel level)
{
_logger->set_level(spdlog::level::level_enum(level));
_level = level;
}

void Log::disable()
{
setLevel(LogLevel::Off);
}

std::shared_ptr<spdlog::logger> Log::_logger = LoggerFactory::createLogger();
void Log::_handleMessage(LogLevel level, std::string_view message)
{
auto &levelName = EnumInfo::getName(level);
auto record = fmt::format("[Brayns][{}] {}", levelName, message);
std::cout << record << '\n';
}
} // namespace brayns
34 changes: 21 additions & 13 deletions src/brayns/core/utils/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

#pragma once

#define SPDLOG_HEADER_ONLY
#include <spdlog/fmt/ostr.h>
#include <spdlog/spdlog.h>
#include <string>
#include <string_view>

#include <fmt/format.h>

#include <brayns/core/utils/EnumInfo.h>

Expand All @@ -35,14 +36,14 @@ namespace brayns
*/
enum class LogLevel
{
Trace = spdlog::level::trace,
Debug = spdlog::level::debug,
Info = spdlog::level::info,
Warn = spdlog::level::warn,
Error = spdlog::level::err,
Critical = spdlog::level::critical,
Off = spdlog::level::off,
Count = spdlog::level::n_levels
Trace,
Debug,
Info,
Warn,
Error,
Critical,
Off,
Count,
};

template<>
Expand Down Expand Up @@ -78,7 +79,12 @@ class Log
template<typename... Args>
static void log(LogLevel level, fmt::format_string<Args...> format, Args &&...args)
{
_logger->log(spdlog::level::level_enum(level), format, std::forward<Args>(args)...);
if (level < _level)
{
return;
}
auto message = fmt::format(format, std::forward<Args>(args)...);
_handleMessage(level, message);
}

/**
Expand Down Expand Up @@ -160,6 +166,8 @@ class Log
}

private:
static std::shared_ptr<spdlog::logger> _logger;
static inline LogLevel _level = LogLevel::Info;

static void _handleMessage(LogLevel level, std::string_view message);
};
} // namespace brayns
2 changes: 1 addition & 1 deletion src/brayns/core/utils/parsing/RangeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <brayns/core/utils/string/StringInfo.h>
#include <brayns/core/utils/string/StringParser.h>

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

#include <algorithm>
#include <stdexcept>
Expand Down