Skip to content

Commit 3671d61

Browse files
Refactor logging system: Migrate log functionality to new 'logging' namespace
1 parent 88b1cb2 commit 3671d61

10 files changed

Lines changed: 48 additions & 48 deletions

File tree

example/example.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "log/log.h"
2-
#include "log/sink.h"
1+
#include "logging/log.h"
2+
#include "logging/sink.h"
33
#include "web/env.h"
44
#include "web/loop.h"
55
#include "web/response.h"
@@ -33,8 +33,8 @@ int main(){
3333

3434

3535
// Configure the logging system
36-
log::add_sink(
37-
std::make_unique<log::sink::file>("app.log")
36+
logging::add_sink(
37+
std::make_unique<logging::sink::file>("app.log")
3838
);
3939

4040

src/concurrent/hp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <ranges>
33
#include <algorithm>
44
#include "concurrent/hp.h"
5-
#include "log/log.h"
5+
#include "logging/log.h"
66
namespace concurrent {
77

88
namespace detail {
@@ -60,7 +60,7 @@ void hazard_recorder::scan_retired(std::vector<retired_ptr_t>& retired_list){
6060
deleter(ptr);
6161
return true; // Remove from the list
6262
}
63-
log::sync::error("retired pointer has no deleter.");
63+
logging::sync::error("retired pointer has no deleter.");
6464
std::terminate();
6565
}
6666
);
@@ -73,10 +73,10 @@ hazard_recorder::~hazard_recorder() {
7373

7474
this->scan_retired(g_retired);
7575
if (g_retired.size() > 0) {
76-
log::sync::error("Hazard manager still has {} retired pointers after destruction.", g_retired.size());
76+
logging::sync::error("Hazard manager still has {} retired pointers after destruction.", g_retired.size());
7777
for (const auto& [index, record] : std::views::enumerate(this->records)) {
7878
if (record.active.load(std::memory_order_acquire)) {
79-
log::sync::error("Hazard record {} is still active.", index);
79+
logging::sync::error("Hazard record {} is still active.", index);
8080
}
8181
}
8282

src/io/ctx.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "coro/thread.h"
1212
#include "io/ctx.h"
13-
#include "log/log.h"
13+
#include "logging/log.h"
1414

1515
namespace io::detail {
1616

@@ -34,9 +34,9 @@ void ctx::worker(std::stop_token st){
3434
if (submit_count >= submit_threshold) {
3535
auto submit_ret = io_uring_submit(&ring);
3636
if (submit_ret < 0) {
37-
log::async::error("io_uring_submit failed: {}", strerror(-submit_ret));
37+
logging::async::error("io_uring_submit failed: {}", strerror(-submit_ret));
3838
} else {
39-
log::async::debug("Submitted {} requests to io_uring", submit_ret);
39+
logging::async::debug("Submitted {} requests to io_uring", submit_ret);
4040
submit_count = 0;
4141
}
4242
}
@@ -45,9 +45,9 @@ void ctx::worker(std::stop_token st){
4545
this->pending_req_count.fetch_add(pending_req_count, std::memory_order_acq_rel);
4646
auto submit_ret = io_uring_submit(&ring);
4747
if (submit_ret < 0) {
48-
log::async::error("io_uring_submit failed: {}", strerror(-submit_ret));
48+
logging::async::error("io_uring_submit failed: {}", strerror(-submit_ret));
4949
} else {
50-
log::async::debug("Submitted {} requests to io_uring", submit_ret);
50+
logging::async::debug("Submitted {} requests to io_uring", submit_ret);
5151
submit_count = 0;
5252
pending_req_count = 0;
5353
}
@@ -84,15 +84,15 @@ void ctx::handle_cqes(io_uring_cqe* cqe) {
8484
}
8585
}
8686
} else {
87-
log::async::error("Unknown user data type in cqe");
87+
logging::async::error("Unknown user data type in cqe");
8888
}
8989
}
9090
);
9191
this->usr_data_pool.deallocate(data); // Clean up the user data
9292
}
9393
io_uring_cq_advance(&ring, count);
9494
this->pending_req_count.fetch_sub(processed_req, std::memory_order_acq_rel);
95-
log::async::debug("Processed {} completed requests", count);
95+
logging::async::debug("Processed {} completed requests", count);
9696
}
9797

9898

@@ -107,10 +107,10 @@ void ctx::start_listen(std::stop_token st){
107107
int ret = io_uring_wait_cqes(&ring, &cqe, 1, nullptr, &sigmask);
108108

109109
if (ret == -EINTR){
110-
log::async::debug("io_uring_wait_cqes interrupted by signal, checking for stop request");
110+
logging::async::debug("io_uring_wait_cqes interrupted by signal, checking for stop request");
111111
continue; // Interrupted by signal, continue waiting
112112
} else if (ret < 0) {
113-
log::sync::error("io_uring_wait_cqes failed: {}", strerror(-ret));
113+
logging::sync::error("io_uring_wait_cqes failed: {}", strerror(-ret));
114114
break;
115115
} else {
116116
this->handle_cqes(cqe);
@@ -135,9 +135,9 @@ void ctx::clean_up() {
135135
this->pending_req_count.fetch_add(pending_req_count, std::memory_order_acq_rel);
136136
auto submit_ret = io_uring_submit(&ring);
137137
if (submit_ret < 0) {
138-
log::async::error("io_uring_submit failed: {}", strerror(-submit_ret));
138+
logging::async::error("io_uring_submit failed: {}", strerror(-submit_ret));
139139
} else {
140-
log::async::debug("Submitted {} requests to io_uring", submit_ret);
140+
logging::async::debug("Submitted {} requests to io_uring", submit_ret);
141141
}
142142

143143

@@ -153,7 +153,7 @@ void ctx::clean_up() {
153153
if (ret == -ETIME){
154154
continue; // Timeout, continue waiting
155155
} else if (ret < 0) {
156-
log::sync::error("io_uring_wait_cqes failed: {}", strerror(-ret));
156+
logging::sync::error("io_uring_wait_cqes failed: {}", strerror(-ret));
157157
break;
158158
} else {
159159
this->handle_cqes(cqe);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <format>
44
#include <source_location>
55
#include <concepts>
6-
namespace log{
6+
namespace logging{
77

88
enum class level{
99
error,

src/log/log.h renamed to src/logging/log.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#include <format>
1111
#include <vector>
1212

13-
#include "log/sink.h"
14-
#include "log/common.h"
13+
#include "logging/sink.h"
14+
#include "logging/common.h"
1515

1616
#include "concurrent/mpsc_ringbuffer.h"
1717

18-
namespace log{
18+
namespace logging {
1919

2020
namespace detail {
2121

@@ -204,7 +204,7 @@ inline void add_sink(std::unique_ptr<sink::basic> s) {
204204
namespace sync {
205205
template<level lvl, typename... args_t>
206206
void log(format_string_wrapper<args_t...> fmt_w, args_t&&... args){
207-
if constexpr (lvl <= log::max_level) {
207+
if constexpr (lvl <= logging::max_level) {
208208
detail::logger::get_instance()->log(
209209
detail::packet::make<lvl>(system_clock::now(), fmt_w, std::forward<args_t>(args)...)
210210
);
@@ -242,7 +242,7 @@ namespace async{
242242

243243
template<level lvl, typename... args_t>
244244
void log(format_string_wrapper<args_t...> fmt_w, args_t&&... args){
245-
if constexpr (lvl <= log::max_level) {
245+
if constexpr (lvl <= logging::max_level) {
246246
detail::tls().push(
247247
detail::packet::make<lvl>(system_clock::now(), fmt_w, std::forward<args_t>(args)...)
248248
);

src/log/sink.h renamed to src/logging/sink.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#include <string_view>
1212
#include <utility>
1313

14-
#include "common.h"
14+
#include "logging/common.h"
1515
#include "meta.h"
1616

17-
namespace log::sink {
17+
namespace logging::sink {
1818

1919

2020
namespace detail {
@@ -138,7 +138,7 @@ class basic : public detail::fmt_ostream {
138138
}
139139
}
140140
private:
141-
log::level level{max_level};
141+
logging::level level{max_level};
142142
std::mutex mutex{};
143143
};
144144

src/web/loop.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <system_error>
44
#include <utility>
55
#include <filesystem>
6-
#include "log/log.h"
6+
#include "logging/log.h"
77

88
#include "web/loop.h"
99
#include "web/mime.h"
@@ -35,7 +35,7 @@ coro::simple_task async_handle_connection(int fd, ip::v4 a) {
3535
};
3636

3737
if (bytes_read <= 0) {
38-
log::async::error("Failed to read from {}: {}",
38+
logging::async::error("Failed to read from {}: {}",
3939
client_addr.to_string(), io::error::msg
4040
);
4141
co_return;
@@ -66,7 +66,7 @@ coro::simple_task async_handle_connection(int fd, ip::v4 a) {
6666

6767

6868
} else {
69-
log::async::error("Failed to parse request from {}", client_addr.to_string());
69+
logging::async::error("Failed to parse request from {}", client_addr.to_string());
7070
co_await web::response::error(http::response::status_code::bad_request)
7171
.settings({fd_w.get(), client_addr, timeout});
7272
co_return;
@@ -87,17 +87,17 @@ coro::simple_task server_loop(int32_t f) {
8787
switch (ret) {
8888
case io::error::SYS:
8989
case io::error::CTX_CLOSED:
90-
log::async::error("Failed to accept connection: {}", io::error::msg);
90+
logging::async::error("Failed to accept connection: {}", io::error::msg);
9191
co_return;
9292
case io::error::TIMEOUT:
93-
log::async::debug("Accept timed out, retrying...");
93+
logging::async::debug("Accept timed out, retrying...");
9494
continue;
9595
default:
9696
break;
9797

9898
}
9999
auto ipv4_addr = ip::v4::from_sockaddr_in(client_addr);
100-
log::async::info("Fd[{}]: Accepted connection from {}", fd, ipv4_addr.to_string());
100+
logging::async::info("Fd[{}]: Accepted connection from {}", fd, ipv4_addr.to_string());
101101
async_handle_connection(ret, ipv4_addr);
102102
}
103103

@@ -161,7 +161,7 @@ void add_static_file_router(){
161161
}
162162

163163
auto relative_path_str = std::format("/{}", full_path.lexically_relative(root).c_str());
164-
log::sync::info("Adding file `{}` to router as `{}`", full_path.string(), relative_path_str);
164+
logging::sync::info("Adding file `{}` to router as `{}`", full_path.string(), relative_path_str);
165165

166166
routing::env::static_routers().push_back(
167167
{
@@ -183,7 +183,7 @@ void add_static_file_router(){
183183

184184
// Register static file routers
185185
for (auto& [head_router, router] : routing::env::static_routers()) {
186-
log::sync::info("Adding file router: {}", router.name);
186+
logging::sync::info("Adding file router: {}", router.name);
187187
routing::get(router.name, router);
188188
routing::head(head_router.name, head_router);
189189
}

src/web/reponse.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <cstdint>
33
#include <vector>
44

5-
#include "log/log.h"
5+
#include "logging/log.h"
66
#include "web/response.h"
77
#include "web/routing.h"
88

@@ -36,7 +36,7 @@ task msg(const http::response::msg& msg){
3636
timeout
3737
};
3838
if (res <= 0) {
39-
log::async::error(
39+
logging::async::error(
4040
"Failed to send response for `{}`: `{}`",
4141
client_addr.to_string(), io::error::msg
4242
);
@@ -79,7 +79,7 @@ task error(http::response::status_code code){
7979
timeout
8080
};
8181
if (res <= 0) {
82-
log::async::error(
82+
logging::async::error(
8383
"Failed to send response for `{}`: `{}`",
8484
client_addr.to_string(), io::error::msg
8585
);
@@ -144,7 +144,7 @@ task file(const std::string& content_type, std::span<std::byte> content){
144144
};
145145

146146
if (res <= 0) {
147-
log::async::error(
147+
logging::async::error(
148148
"Failed to send response for {} : {}",
149149
client_addr.to_string(), io::error::msg
150150
);
@@ -170,7 +170,7 @@ task file(const std::string& content_type, std::span<std::byte> content){
170170
};
171171

172172
if (res <= 0) {
173-
log::async::error(
173+
logging::async::error(
174174
"Failed to send response for {} : {}",
175175
client_addr.to_string(), io::error::msg
176176
);
@@ -202,7 +202,7 @@ task file(const std::string& content_type, std::span<std::byte> content){
202202
};
203203

204204
if (res <= 0) {
205-
log::async::error(
205+
logging::async::error(
206206
"Failed to send response for {} : {}",
207207
client_addr.to_string(), io::error::msg
208208
);

src/web/response.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ struct task {
3232
struct final_awaiter {
3333
bool await_ready() noexcept { return false; }
3434
void await_resume() noexcept {}
35-
std::coroutine_handle<> await_suspend(std::coroutine_handle<promise_type> h){
35+
std::coroutine_handle<> await_suspend(std::coroutine_handle<promise_type> h) noexcept {
3636
return h.promise().previous;
3737
}
3838
};
3939

4040
auto final_suspend() noexcept {
4141
return final_awaiter{};
4242
}
43-
void unhandled_exception(){}
43+
void unhandled_exception() noexcept {}
4444

45-
void return_value(int64_t v){
45+
void return_value(int64_t v) noexcept {
4646
ret = v;
4747
}
4848

test/log/log.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <string>
33
#include <system_error>
44

5-
#include "log/log.h"
5+
#include "logging/log.h"
66

77

88
using namespace boost::ut;
@@ -15,7 +15,7 @@ suite<"Logging Sink Tests"> _ = [] {
1515
constexpr size_t times = 1000;
1616

1717
{
18-
log::sink::file file_sink(filename, 1024); // 1KB max size for testing
18+
logging::sink::file file_sink(filename, 1024); // 1KB max size for testing
1919

2020
for (auto _ : std::views::iota(0uz, times)) {
2121
file_sink.fmt_to("{}", msg);

0 commit comments

Comments
 (0)