/src/WasmEdge/include/common/spdlog.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | |
4 | | //===-- wasmedge/common/spdlog.h - Logging system -------------------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the logging system linkage. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | |
16 | | #include "common/filesystem.h" |
17 | | #include "common/fmt.h" |
18 | | #include "common/int128.h" |
19 | | #define SPDLOG_NO_EXCEPTIONS 1 |
20 | | #include "spdlog/spdlog.h" |
21 | | |
22 | | namespace WasmEdge { |
23 | | namespace Log { |
24 | | |
25 | | void setLogOff(); |
26 | | |
27 | | void setTraceLoggingLevel(); |
28 | | |
29 | | void setDebugLoggingLevel(); |
30 | | |
31 | | void setInfoLoggingLevel(); |
32 | | |
33 | | void setWarnLoggingLevel(); |
34 | | |
35 | | void setErrorLoggingLevel(); |
36 | | |
37 | | void setCriticalLoggingLevel(); |
38 | | |
39 | | /// Set the logging level from a string. |
40 | | /// Supported values: off, trace, debug, info, warning, error, fatal. |
41 | | /// Returns true if level was set successfully, false if invalid. |
42 | | bool setLoggingLevelFromString(std::string_view Level); |
43 | | |
44 | | void setLoggingCallback( |
45 | | std::function<void(const spdlog::details::log_msg &)> Callback); |
46 | | |
47 | | } // namespace Log |
48 | | } // namespace WasmEdge |
49 | | |
50 | | template <> |
51 | | struct fmt::formatter<std::filesystem::path> |
52 | | : fmt::formatter<std::string_view> { |
53 | | template <typename FmtCtx> |
54 | | auto format(const std::filesystem::path &Path, FmtCtx &Ctx) WASMEDGE_FMT_CONST |
55 | 0 | -> decltype(Ctx.out()) { |
56 | | // mimic std::quoted |
57 | 0 | constexpr const char Delimiter = '"'; |
58 | 0 | constexpr const char Escape = '\\'; |
59 | 0 | auto Quoted = fmt::memory_buffer(); |
60 | 0 | auto Iter = std::back_inserter(Quoted); |
61 | 0 | *Iter++ = Delimiter; |
62 | 0 | for (const auto C : Path.u8string()) { |
63 | 0 | if (C == Delimiter || C == Escape) { |
64 | 0 | *Iter++ = Escape; |
65 | 0 | } |
66 | 0 | *Iter++ = C; |
67 | 0 | } |
68 | 0 | *Iter++ = Delimiter; |
69 | 0 | return fmt::formatter<std::string_view>::format( |
70 | 0 | std::string_view(Quoted.data(), Quoted.size()), Ctx); |
71 | 0 | } |
72 | | }; |