mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-21 19:18:55 +00:00
Remove gsl subodule and replace with a local copy of gsl-lite Refactor for onnxruntime::make_unique gsl::span size and index are now size_t Remove lambda auto argument type detection. Remove constexpr from fail_fast in gsl due to Linux not being happy. Comment out std::stream support due to MacOS std lib broken. Move make_unique into include/core/common so it is accessible for server builds. Relax requirements for onnxruntime/test/providers/cpu/ml/write_scores_test.cc due to x86 build. Add ONNXRUNTIME_ROOT to Server Lib includes so gsl is recognized
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "core/common/logging/capture.h"
|
|
#include "core/common/logging/logging.h"
|
|
#include "gsl/gsl"
|
|
|
|
namespace onnxruntime {
|
|
namespace logging {
|
|
|
|
void Capture::CapturePrintf(msvc_printf_check const char* format, ...) {
|
|
va_list arglist;
|
|
va_start(arglist, format);
|
|
|
|
ProcessPrintf(format, arglist);
|
|
|
|
va_end(arglist);
|
|
}
|
|
|
|
// from https://github.com/KjellKod/g3log/blob/master/src/logcapture.cpp LogCapture::capturef
|
|
// License: https://github.com/KjellKod/g3log/blob/master/LICENSE
|
|
// Modifications Copyright (c) Microsoft.
|
|
void Capture::ProcessPrintf(msvc_printf_check const char* format, va_list args) {
|
|
static constexpr auto kTruncatedWarningText = "[...truncated...]";
|
|
static const int kMaxMessageSize = 2048;
|
|
char message_buffer[kMaxMessageSize];
|
|
const auto message = gsl::make_span(message_buffer);
|
|
|
|
bool error = false;
|
|
bool truncated = false;
|
|
|
|
#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) && !defined(__GNUC__))
|
|
errno = 0;
|
|
const int nbrcharacters = vsnprintf_s(message.data(), message.size(), _TRUNCATE, format, args);
|
|
if (nbrcharacters < 0) {
|
|
error = errno != 0;
|
|
truncated = !error;
|
|
}
|
|
#else
|
|
const int nbrcharacters = vsnprintf(message.data(), message.size(), format, args);
|
|
error = nbrcharacters < 0;
|
|
truncated = (nbrcharacters >= 0 && static_cast<gsl::index>(nbrcharacters) > message.size());
|
|
#endif
|
|
|
|
if (error) {
|
|
stream_ << "\n\tERROR LOG MSG NOTIFICATION: Failure to successfully parse the message";
|
|
stream_ << '"' << format << '"' << std::endl;
|
|
} else if (truncated) {
|
|
stream_ << message.data() << kTruncatedWarningText;
|
|
} else {
|
|
stream_ << message.data();
|
|
}
|
|
}
|
|
|
|
Capture::~Capture() {
|
|
if (logger_ != nullptr) {
|
|
logger_->Log(*this);
|
|
}
|
|
}
|
|
} // namespace logging
|
|
} // namespace onnxruntime
|