Skip to content

Commit 0bfc3d0

Browse files
committed
refactor: make log the canonical logging owner
2 parents 4ccca73 + 3890d0a commit 0bfc3d0

10 files changed

Lines changed: 1568 additions & 406 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 76 additions & 332 deletions
Large diffs are not rendered by default.

‎README.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The **log module** provides a clean, stable, and high-level logging API
44
for Vix applications.
55

6-
It is built as a **facade** over the internal `vix::utils::Logger`,
6+
It owns the canonical Vix logging implementation,
77
exposing a consistent and developer-friendly interface while reusing
88
a powerful logging backend.
99

@@ -28,12 +28,13 @@ The module is designed to be:
2828
## Architecture
2929

3030
```
31-
vix::utils::Logger → core logging engine
32-
vix::log → public facade (this module)
31+
vix::log::Logger → logging engine
32+
vix::log → public logging capability
3333
```
3434

3535
The `log` module does not implement logging itself.
36-
It delegates all operations to `vix::utils::Logger`.
36+
Historical `vix::utils::Logger` remains a temporary compatibility alias to
37+
the canonical implementation.
3738

3839
## Quick Start
3940

@@ -160,4 +161,3 @@ No direct dependency on spdlog is exposed publicly.
160161

161162
MIT
162163
Part of the Vix.cpp project.
163-

‎cmake/vix_logConfig.cmake.in‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
include(CMakeFindDependencyMacro)
44

5-
find_dependency(vix_utils CONFIG REQUIRED)
5+
find_dependency(fmt CONFIG REQUIRED)
6+
find_dependency(spdlog CONFIG REQUIRED)
67

78
include("${CMAKE_CURRENT_LIST_DIR}/vix_logTargets.cmake")
89

‎include/vix/log/ConsoleSync.hpp‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @file ConsoleSync.hpp
3+
* @brief Shared console synchronization used by the logging implementation.
4+
*/
5+
#ifndef VIX_LOG_CONSOLE_SYNC_HPP
6+
#define VIX_LOG_CONSOLE_SYNC_HPP
7+
8+
#include <condition_variable>
9+
#include <mutex>
10+
11+
namespace vix::log
12+
{
13+
inline std::mutex &console_mutex()
14+
{
15+
static std::mutex mutex;
16+
return mutex;
17+
}
18+
19+
inline std::mutex &banner_mutex()
20+
{
21+
static std::mutex mutex;
22+
return mutex;
23+
}
24+
25+
inline std::condition_variable &console_cv()
26+
{
27+
static std::condition_variable cv;
28+
return cv;
29+
}
30+
31+
inline bool &console_banner_done()
32+
{
33+
static bool done = true;
34+
return done;
35+
}
36+
37+
inline void console_wait_banner()
38+
{
39+
std::unique_lock<std::mutex> lock(banner_mutex());
40+
console_cv().wait(lock, [] { return console_banner_done(); });
41+
}
42+
43+
inline void console_mark_banner_done()
44+
{
45+
{
46+
std::lock_guard<std::mutex> lock(banner_mutex());
47+
console_banner_done() = true;
48+
}
49+
console_cv().notify_all();
50+
}
51+
52+
inline void console_reset_banner()
53+
{
54+
std::lock_guard<std::mutex> lock(banner_mutex());
55+
console_banner_done() = false;
56+
}
57+
}
58+
59+
#endif // VIX_LOG_CONSOLE_SYNC_HPP

‎include/vix/log/LogAdapter.hpp‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@
2222
#include <vix/log/LogContext.hpp>
2323
#include <vix/log/LogFormat.hpp>
2424
#include <vix/log/LogLevel.hpp>
25-
#include <vix/utils/Logger.hpp>
25+
#include <vix/log/Logger.hpp>
2626

2727
namespace vix::log
2828
{
2929

3030
/**
3131
* @class LogAdapter
32-
* @brief Public adapter that bridges `vix::log` to `vix::utils::Logger`.
32+
* @brief Public adapter over the canonical Vix logger implementation.
3333
*
34-
* This class does not implement logging itself.
35-
* It provides a stable public API for the `vix::log` module while
36-
* delegating the actual work to the existing utils logger backend.
34+
* This class provides the public `vix::log` API while delegating to the
35+
* logging implementation owned by this module.
3736
*/
3837
class LogAdapter
3938
{
@@ -172,55 +171,55 @@ namespace vix::log
172171
template <typename... Args>
173172
void log(LogLevel level, fmt::format_string<Args...> fmtstr, Args &&...args)
174173
{
175-
backend().log(to_utils_level(level), fmtstr, std::forward<Args>(args)...);
174+
backend().log(to_logger_level(level), fmtstr, std::forward<Args>(args)...);
176175
}
177176

178177
/**
179178
* @brief Log a formatted message with key/value pairs.
180179
*
181-
* This delegates to `vix::utils::Logger::logf`.
180+
* This delegates to the canonical logger implementation.
182181
*/
183182
template <typename... Args>
184183
void logf(LogLevel level, const std::string &message, Args &&...kvpairs)
185184
{
186-
backend().logf(to_utils_level(level), message, std::forward<Args>(kvpairs)...);
185+
backend().logf(to_logger_level(level), message, std::forward<Args>(kvpairs)...);
187186
}
188187

189188
private:
190189
/**
191-
* @brief Access the underlying utils logger backend.
190+
* @brief Access the underlying logger implementation.
192191
*/
193-
[[nodiscard]] static vix::utils::Logger &backend();
192+
[[nodiscard]] static Logger &backend();
194193

195194
/**
196-
* @brief Convert a public log level to utils logger level.
195+
* @brief Convert a public log level to implementation level.
197196
*/
198-
[[nodiscard]] static vix::utils::Logger::Level to_utils_level(LogLevel level) noexcept;
197+
[[nodiscard]] static Logger::Level to_logger_level(LogLevel level) noexcept;
199198

200199
/**
201-
* @brief Convert a utils logger level to public log level.
200+
* @brief Convert an implementation level to public log level.
202201
*/
203-
[[nodiscard]] static LogLevel from_utils_level(vix::utils::Logger::Level level) noexcept;
202+
[[nodiscard]] static LogLevel from_logger_level(Logger::Level level) noexcept;
204203

205204
/**
206-
* @brief Convert a public log format to utils logger format.
205+
* @brief Convert a public log format to implementation format.
207206
*/
208-
[[nodiscard]] static vix::utils::Logger::Format to_utils_format(LogFormat format) noexcept;
207+
[[nodiscard]] static Logger::Format to_logger_format(LogFormat format) noexcept;
209208

210209
/**
211-
* @brief Convert a utils logger format to public log format.
210+
* @brief Convert an implementation format to public log format.
212211
*/
213-
[[nodiscard]] static LogFormat from_utils_format(vix::utils::Logger::Format format) noexcept;
212+
[[nodiscard]] static LogFormat from_logger_format(Logger::Format format) noexcept;
214213

215214
/**
216-
* @brief Convert a public log context to utils logger context.
215+
* @brief Convert a public log context to implementation context.
217216
*/
218-
[[nodiscard]] static vix::utils::Logger::Context to_utils_context(const LogContext &ctx);
217+
[[nodiscard]] static Logger::Context to_logger_context(const LogContext &ctx);
219218

220219
/**
221-
* @brief Convert a utils logger context to public log context.
220+
* @brief Convert an implementation context to public log context.
222221
*/
223-
[[nodiscard]] static LogContext from_utils_context(const vix::utils::Logger::Context &ctx);
222+
[[nodiscard]] static LogContext from_logger_context(const Logger::Context &ctx);
224223
};
225224

226225
} // namespace vix::log

‎include/vix/log/LogFormat.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ namespace vix::log
2222
* @enum LogFormat
2323
* @brief Public structured logging output formats.
2424
*
25-
* These formats map to the underlying `vix::utils::Logger::Format`
26-
* values through the log adapter.
25+
* These formats map to the logging implementation format through the
26+
* log adapter.
2727
*/
2828
enum class LogFormat
2929
{

‎include/vix/log/LogLevel.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace vix::log
2323
* @brief Public logging severity levels for the Vix log module.
2424
*
2525
* These values are intentionally stable and map to the underlying
26-
* `vix::utils::Logger::Level` values through the log adapter.
26+
* implementation level values through the log adapter.
2727
*/
2828
enum class LogLevel
2929
{

0 commit comments

Comments
 (0)