Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/include/common/spdlog.h
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
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 linkage of logging system.
12
///
13
//===----------------------------------------------------------------------===//
14
#pragma once
15
16
#include "common/filesystem.h"
17
#include "common/int128.h"
18
#define SPDLOG_NO_EXCEPTIONS 1
19
#include "spdlog/spdlog.h"
20
21
namespace WasmEdge {
22
namespace Log {
23
24
void setLogOff();
25
26
void setTraceLoggingLevel();
27
28
void setDebugLoggingLevel();
29
30
void setInfoLoggingLevel();
31
32
void setWarnLoggingLevel();
33
34
void setErrorLoggingLevel();
35
36
void setCriticalLoggingLevel();
37
38
void setLoggingCallback(
39
    std::function<void(const spdlog::details::log_msg &)> Callback);
40
41
} // namespace Log
42
} // namespace WasmEdge
43
44
template <>
45
struct fmt::formatter<std::filesystem::path>
46
    : fmt::formatter<std::string_view> {
47
  fmt::format_context::iterator format(const std::filesystem::path &Path,
48
0
                                       fmt::format_context &Ctx) const {
49
    // mimic std::quoted
50
0
    constexpr const char Delimiter = '"';
51
0
    constexpr const char Escape = '\\';
52
0
    auto Quoted = fmt::memory_buffer();
53
0
    auto Iter = std::back_inserter(Quoted);
54
0
    *Iter++ = Delimiter;
55
0
    for (const auto C : Path.u8string()) {
56
0
      if (C == Delimiter || C == Escape) {
57
0
        *Iter++ = Escape;
58
0
      }
59
0
      *Iter++ = C;
60
0
    }
61
0
    *Iter++ = Delimiter;
62
0
    return fmt::formatter<std::string_view>::format(
63
0
        std::string_view(Quoted.data(), Quoted.size()), Ctx);
64
0
  }
65
};