Allow log output to a file (#252)

Co-authored-by: star9029 <hengxings783@gmail.com>
This commit is contained in:
ykiko
2025-09-14 16:45:07 +08:00
committed by GitHub
parent d502eee53f
commit e8f5f6ba64
23 changed files with 323 additions and 322 deletions

View File

@@ -1,4 +1,4 @@
#include "Support/Logger.h"
#include "Support/Logging.h"
#include "Server/Server.h"
namespace clice {
@@ -121,7 +121,7 @@ Server::Server() {
async::Task<> Server::on_receive(json::Value value) {
auto object = value.getAsObject();
if(!object) [[unlikely]] {
log::fatal("Invalid LSP message, not an object: {}", value);
logging::fatal("Invalid LSP message, not an object: {}", value);
}
/// If the json object has an `id`, it's a request,
@@ -132,7 +132,7 @@ async::Task<> Server::on_receive(json::Value value) {
if(auto result = object->getString("method")) {
method = *result;
} else [[unlikely]] {
log::warn("Invalid LSP message, method not found: {}", value);
logging::warn("Invalid LSP message, method not found: {}", value);
if(id) {
co_await response(std::move(*id),
proto::ErrorCodes::InvalidRequest,
@@ -149,7 +149,7 @@ async::Task<> Server::on_receive(json::Value value) {
/// Handle request and notification separately.
auto it = callbacks.find(method);
if(it == callbacks.end()) {
log::info("Ignore unhandled method: {}", method);
logging::info("Ignore unhandled method: {}", method);
co_return;
}
@@ -157,24 +157,24 @@ async::Task<> Server::on_receive(json::Value value) {
auto current_id = client_request_id++;
auto start_time = std::chrono::steady_clock::now();
log::info("<-- Handling request: {}({})", method, current_id);
logging::info("<-- Handling request: {}({})", method, current_id);
auto result = co_await it->second(*this, std::move(params));
co_await response(std::move(*id), std::move(result));
auto end_time = std::chrono::steady_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
log::info("--> Handled request: {}({}) {}ms", method, current_id, duration.count());
logging::info("--> Handled request: {}({}) {}ms", method, current_id, duration.count());
} else {
auto start_time = std::chrono::steady_clock::now();
log::info("<-- Handling notification: {}", method);
logging::info("<-- Handling notification: {}", method);
auto result = co_await it->second(*this, std::move(params));
auto end_time = std::chrono::steady_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
log::info("--> Handled notification: {} {}ms", method, duration.count());
logging::info("--> Handled notification: {} {}ms", method, duration.count());
}
co_return;