Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#if !defined(ORT_EP_API_ADAPTER_HEADER_INCLUDED)
#error "This header should not be included directly. Include ep/adapters.h instead."
#endif
 
#include "core/common/logging/logging.h"
#include "core/common/path_string.h"
 
namespace onnxruntime {
namespace ep {
namespace adapter {
 
struct Logger {
  Logger(const OrtLogger* logger) : logger_(logger) {}
 
  bool OutputIsEnabled(logging::Severity severity, logging::DataType /* data_type */) const noexcept {
    return ((OrtLoggingLevel)severity >= logger_.GetLoggingSeverityLevel());
  }
 
  void Log(logging::Severity severity,
           const char* file_path,
           int line_number,
           const char* func_name,
           const char* message) const noexcept {
    auto path_string = onnxruntime::ToPathString(file_path);
    logger_.LogMessage((OrtLoggingLevel)severity,
                       path_string.c_str(),
                       line_number,
                       func_name,
                       message);
  }
 
 private:
  Ort::Logger logger_;
};
 
class LoggingManager final {
 public:
  static bool HasDefaultLogger() { return nullptr != instance_; }
  static const Logger& DefaultLogger() { return *instance_; }
  static void CreateDefaultLogger(const OrtLogger* logger) {
    instance_ = new Logger(logger);
  }
  static void DestroyDefaultLogger() {
    delete instance_;
    instance_ = nullptr;
  }
 
 private:
  inline static Logger* instance_ = nullptr;
};
 
namespace detail {
struct LoggerCapture {
  LoggerCapture(const Logger& logger,
                logging::Severity severity,
                const char* category,
                logging::DataType dataType,
                const CodeLocation& location) : logger_{logger},
                                                severity_{severity},
                                                category_{category},
                                                data_type_{dataType},
                                                location_{location} {}
 
  ~LoggerCapture() {
    logger_.Log(severity_, location_.file_and_path.c_str(), location_.line_num,
                location_.function.c_str(), stream_.str().c_str());
  }
 
  std::ostream& Stream() noexcept {
    return stream_;
  }
 
  const Logger& logger_;
  logging::Severity severity_;
  const char* category_;
  logging::DataType data_type_;
  const CodeLocation& location_;
  std::ostringstream stream_;
};
 
// Helper functions to dispatch to the correct Capture type based on logger type
inline ::onnxruntime::logging::Capture CreateMessageCapture(
    const ::onnxruntime::logging::Logger& logger,
    ::onnxruntime::logging::Severity severity,
    const char* category,
    ::onnxruntime::logging::DataType datatype,
    const CodeLocation& location) {
  return ::onnxruntime::logging::Capture(logger, severity, category, datatype, location);
}
 
inline detail::LoggerCapture CreateMessageCapture(
    const Logger& logger,
    ::onnxruntime::logging::Severity severity,
    const char* category,
    ::onnxruntime::logging::DataType datatype,
    const CodeLocation& location) {
  return detail::LoggerCapture(logger, severity, category, datatype, location);
}
 
}  // namespace detail
}  // namespace adapter
}  // namespace ep
}  // namespace onnxruntime
 
// Undefine and redefine logging macros
#undef LOGS_DEFAULT_CATEGORY
#define LOGS_DEFAULT_CATEGORY(severity, category) \
  LOGS_CATEGORY(::onnxruntime::ep::adapter::LoggingManager::DefaultLogger(), severity, category)
 
#undef CREATE_MESSAGE
#define CREATE_MESSAGE(logger, severity, category, datatype) \
  ::onnxruntime::ep::adapter::detail::CreateMessageCapture(logger, ::onnxruntime::logging::Severity::k##severity, category, datatype, ORT_WHERE)