|
1 | 1 | #pragma once |
2 | 2 |
|
3 | | -#include <string> |
4 | | -#include <iostream> |
5 | | -#include <format> |
6 | | -#include <chrono> |
7 | | - |
8 | | -namespace slick_socket |
9 | | -{ |
10 | | - |
11 | | -struct ConsoleLogger final |
12 | | -{ |
13 | | - static ConsoleLogger& instance() |
14 | | - { |
15 | | - static ConsoleLogger instance; |
16 | | - return instance; |
17 | | - } |
18 | | - |
19 | | - void logTrace(const std::string& format, auto&&... args) |
20 | | - { |
21 | | - std::cout << std::format("{:%Y-%m-%d %H:%M:%S} ", std::chrono::system_clock::now()) << "[TRACE] " |
22 | | - << std::vformat(format, std::make_format_args(args...)) << std::endl; |
23 | | - } |
24 | | - void logDebug(const std::string& format, auto&&... args) |
25 | | - { |
26 | | - std::cout << std::format("{:%Y-%m-%d %H:%M:%S} ", std::chrono::system_clock::now()) << "[DEBUG] " |
27 | | - << std::vformat(format, std::make_format_args(args...)) << std::endl; |
28 | | - } |
29 | | - void logInfo(const std::string& format, auto&&... args) |
30 | | - { |
31 | | - std::cout << std::format("{:%Y-%m-%d %H:%M:%S} ", std::chrono::system_clock::now()) << "[INFO] " |
32 | | - << std::vformat(format, std::make_format_args(args...)) << std::endl; |
33 | | - } |
34 | | - void logWarning(const std::string& format, auto&&... args) |
35 | | - { |
36 | | - std::cout << std::format("{:%Y-%m-%d %H:%M:%S} ", std::chrono::system_clock::now()) << "[WARN] " |
37 | | - << std::vformat(format, std::make_format_args(args...)) << std::endl; |
38 | | - } |
39 | | - void logError(const std::string& format, auto&&... args) |
40 | | - { |
41 | | - std::cerr << std::format("{:%Y-%m-%d %H:%M:%S} ", std::chrono::system_clock::now()) << "[ERROR] " |
42 | | - << std::vformat(format, std::make_format_args(args...)) << std::endl; |
43 | | - } |
44 | | - |
45 | | -private: |
46 | | - ConsoleLogger() = default; |
47 | | - ~ConsoleLogger() = default; |
48 | | - ConsoleLogger(const ConsoleLogger&) = delete; |
49 | | - ConsoleLogger& operator=(const ConsoleLogger&) = delete; |
50 | | - ConsoleLogger(ConsoleLogger&&) = delete; |
51 | | - ConsoleLogger& operator=(ConsoleLogger&&) = delete; |
52 | | -}; |
53 | | - |
54 | | -} // namespace slick_socket |
| 3 | +// Logging function placeholders |
| 4 | +// User can assign their own log functions by defining these macros before including this file |
| 5 | +#ifndef LOG_DEBUG |
| 6 | +#define LOG_DEBUG(...) do {} while(0) |
| 7 | +#endif |
| 8 | +#ifndef LOG_INFO |
| 9 | +#define LOG_INFO(...) do {} while(0) |
| 10 | +#endif |
| 11 | +#ifndef LOG_WARN |
| 12 | +#define LOG_WARN(...) do {} while(0) |
| 13 | +#endif |
| 14 | +#ifndef LOG_ERROR |
| 15 | +#define LOG_ERROR(...) do {} while(0) |
| 16 | +#endif |
| 17 | +#ifndef LOG_TRACE |
| 18 | +#define LOG_TRACE(...) do {} while(0) |
| 19 | +#endif |
0 commit comments