Remove spdlog.

This commit is contained in:
ykiko
2024-11-27 22:24:11 +08:00
parent 8857bc1a3a
commit 3ea080c93d
7 changed files with 50 additions and 59 deletions

5
.gitmodules vendored
View File

@@ -8,11 +8,6 @@
url = https://github.com/libuv/libuv.git
branch = v1.x
[submodule "deps/spdlog"]
path = deps/spdlog
url = https://github.com/gabime/spdlog.git
branch = v1.x
[submodule "deps/toml"]
path = deps/toml
url = https://github.com/marzer/tomlplusplus.git

View File

@@ -63,7 +63,6 @@ target_link_libraries(clice-core PUBLIC
# clice executable
add_subdirectory(${CMAKE_SOURCE_DIR}/deps/libuv)
add_subdirectory(${CMAKE_SOURCE_DIR}/deps/spdlog)
set(CLICE_SERVER_SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp)
file(GLOB_RECURSE SRC_FILES "${CMAKE_SOURCE_DIR}/src/Server/*.cpp")
@@ -73,9 +72,8 @@ add_executable(clice ${CLICE_SERVER_SOURCES})
target_include_directories(clice PRIVATE
"${CMAKE_SOURCE_DIR}/deps/toml/include"
"${CMAKE_SOURCE_DIR}/deps/libuv/include"
"${CMAKE_SOURCE_DIR}/deps/spdlog/include"
)
target_link_libraries(clice PRIVATE clice-core uv spdlog::spdlog)
target_link_libraries(clice PRIVATE clice-core uv)
# clice tests
@@ -87,13 +85,11 @@ if(CLICE_ENABLE_TEST)
add_executable(clice-tests ${CLICE_TEST_SOURCES})
target_include_directories(clice-tests PRIVATE
"${CMAKE_SOURCE_DIR}/deps/spdlog/include"
"${CMAKE_SOURCE_DIR}/deps/googletest/googletest/include"
)
target_link_libraries(clice-tests PRIVATE
clice-core
gtest_main
spdlog::spdlog
gtest_main
)
endif()

1
deps/spdlog vendored

Submodule deps/spdlog deleted from a3a0c9d663

View File

@@ -1,46 +1,50 @@
#pragma once
#include <spdlog/spdlog.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <Support/Format.h>
#include <Support/FileSystem.h>
#include <llvm/ADT/SmallString.h>
namespace clice::logger {
namespace clice::log {
inline auto init(std::string_view type, std::string_view filepath) {
if(type == "file") {
llvm::SmallString<128> temp;
temp.append(path::parent_path(path::parent_path(filepath)));
path::append(temp, "logs");
enum class Level {
INFO,
ERROR,
WARN,
DEBUG,
TRACE,
};
auto error = llvm::sys::fs::make_absolute(temp);
auto now = std::chrono::system_clock::now();
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
std::tm now_tm = *std::localtime(&now_c);
std::ostringstream timeStream;
timeStream << std::put_time(&now_tm, "%Y-%m-%d_%H-%M-%S");
std::string logFileName = "clice_" + timeStream.str() + ".log";
path::append(temp, logFileName);
auto logger = spdlog::basic_logger_mt("clice", temp.c_str());
logger->flush_on(spdlog::level::trace);
spdlog::set_default_logger(logger);
} else if(type == "console") {
auto logger = spdlog::stdout_color_mt("clice");
logger->flush_on(spdlog::level::trace);
spdlog::set_default_logger(logger);
}
template <typename... Args>
void log(Level level, std::string_view fmt, Args&&... args) {
namespace chrono = std::chrono;
auto now = chrono::floor<chrono::milliseconds>(chrono::system_clock::now());
auto time = chrono::zoned_time(chrono::current_zone(), now);
auto tag = [&] {
switch(level) {
case Level::INFO: return "\033[32mINFO\033[0m"; // Green
case Level::ERROR: return "\033[31mERROR\033[0m"; // Red
case Level::WARN: return "\033[33mWARN\033[0m"; // Yellow
case Level::DEBUG: return "\033[36mDEBUG\033[0m"; // Cyan
case Level::TRACE: return "\033[35mTRACE\033[0m"; // Magenta
}
}();
llvm::errs() << std::format("[{0:%Y-%m-%d %H:%M:%S}] [{1}] ", time, tag)
<< std::vformat(fmt, std::make_format_args(args...)) << "\n";
}
using spdlog::info;
using spdlog::error;
using spdlog::warn;
using spdlog::debug;
using spdlog::trace;
template <typename... Args>
void info(std::format_string<Args...> fmt, Args&&... args) {
log::log(Level::INFO, fmt.get(), std::forward<Args>(args)...);
}
} // namespace clice::logger
template <typename... Args>
void error(std::format_string<Args...> fmt, Args&&... args) {
log::log(Level::ERROR, fmt.get(), std::forward<Args>(args)...);
}
template <typename... Args>
void warn(std::format_string<Args...> fmt, Args&&... args) {
log::log(Level::WARN, fmt.get(), std::forward<Args>(args)...);
}
} // namespace clice::log

View File

@@ -35,7 +35,7 @@ public:
if(str.consume_front("Content-Length: ") && !str.consumeInteger(10, length) &&
str.consume_front("\r\n\r\n") && str.size() >= length) {
auto result = str.substr(0, length);
pos = str.end() - buffer.begin();
pos = result.end() - buffer.begin();
return result;
}
return {};

View File

@@ -41,8 +41,6 @@ Server::Server() {
}
void Server::run(int argc, const char** argv) {
logger::init("console", argv[0]);
auto dispatch = [this](json::Value value) -> async::promise<void> {
assert(value.kind() == json::Value::Object);
auto object = value.getAsObject();
@@ -52,18 +50,18 @@ void Server::run(int argc, const char** argv) {
auto params = object->get("params");
if(auto id = object->get("id")) {
if(auto iter = requests.find(name); iter != requests.end()) {
logger::info("Request: {0}", name.str());
log::info("Request: {0}", name.str());
co_await iter->second(std::move(*id),
params ? std::move(*params) : json::Value(nullptr));
} else {
logger::error("Unknown request: {0}", name.str());
log::error("Unknown request: {0}", name.str());
}
} else {
if(auto iter = notifications.find(name); iter != notifications.end()) {
logger::info("Notification: {0}", name.str());
log::info("Notification: {0}", name.str());
co_await iter->second(params ? std::move(*params) : json::Value(nullptr));
} else {
logger::error("Unknown notification: {0}", name.str());
log::error("Unknown notification: {0}", name.str());
}
}
}
@@ -245,7 +243,7 @@ async::promise<void> Server::onRangeFormatting(json::Value id,
async::promise<void> Server::updatePCH(llvm::StringRef filepath,
llvm::StringRef content,
llvm::ArrayRef<const char*> args) {
logger::info("Start building PCH for {0}", filepath.str());
log::info("Start building PCH for {0}", filepath.str());
clang::PreambleBounds bounds = {0, 0};
std::string outpath = "/home/ykiko/C++/clice2/build/cache/xxx.pch";
co_await async::schedule_task([&] {
@@ -255,7 +253,7 @@ async::promise<void> Server::updatePCH(llvm::StringRef filepath,
compiler.generatePCH(outpath, bounds.Size, bounds.PreambleEndsAtStartOfLine);
}
});
logger::info("Build PCH success");
log::info("Build PCH success");
auto preamble2 = content.substr(0, bounds.Size).str();
if(bounds.PreambleEndsAtStartOfLine) {
@@ -284,7 +282,7 @@ async::promise<void> Server::buildAST(llvm::StringRef filepath, llvm::StringRef
auto& pch = pchs.at(filepath);
logger::info("Start building AST for {0}", filepath.str());
log::info("Start building AST for {0}", filepath.str());
auto compiler = co_await async::schedule_task([&] {
std::uint32_t boundSize = pch.preamble.size();
bool endAtStart = false;
@@ -299,7 +297,7 @@ async::promise<void> Server::buildAST(llvm::StringRef filepath, llvm::StringRef
compiler->buildAST();
return compiler;
});
logger::info("Build AST success");
log::info("Build AST success");
auto& unit = units[filepath];
unit.state = TranslationUnit::State::Ready;

View File

@@ -3,7 +3,6 @@
#include <gtest/gtest.h>
#include <Support/FileSystem.h>
#include <spdlog/fmt/bundled/color.h>
#include <llvm/Support/MemoryBuffer.h>
#include <source_location>