#pragma once
#include <cstdarg>
#include <cstddef>
#include <cstdlib>
#include <executorch/runtime/platform/compiler.h>
#include <executorch/runtime/platform/types.h>
#ifndef ET_MIN_LOG_LEVEL
#define ET_MIN_LOG_LEVEL Info
#endif
#ifndef ET_LOG_ENABLED
#define ET_LOG_ENABLED 1
#endif
#ifndef PRIu64
#define PRIu64 "llu"
#endif
#ifndef PRId64
#define PRId64 "lld"
#endif
namespace executorch {
namespace runtime {
enum class LogLevel : uint8_t {
Debug,
Info,
Error,
Fatal,
NumLevels,
};
namespace internal {
et_timestamp_t get_log_timestamp();
ET_PRINTFLIKE(6, 0)
void vlogf(
LogLevel level,
et_timestamp_t timestamp,
const char* filename,
const char* function,
size_t line,
const char* format,
va_list args);
ET_PRINTFLIKE(6, 7)
inline void logf(
LogLevel level,
et_timestamp_t timestamp,
const char* filename,
const char* function,
size_t line,
const char* format,
...) {
#if ET_LOG_ENABLED
va_list args;
va_start(args, format);
internal::vlogf(level, timestamp, filename, function, line, format, args);
va_end(args);
#endif }
}
} }
namespace torch {
namespace executor {
using ::executorch::runtime::LogLevel;
} }
#if ET_LOG_ENABLED
#define ET_LOG(_level, _format, ...) \
do { \
const auto _log_level = ::executorch::runtime::LogLevel::_level; \
if (static_cast<uint32_t>(_log_level) >= \
static_cast<uint32_t>( \
::executorch::runtime::LogLevel::ET_MIN_LOG_LEVEL)) { \
const auto _timestamp = \
::executorch::runtime::internal::get_log_timestamp(); \
::executorch::runtime::internal::logf( \
_log_level, \
_timestamp, \
ET_SHORT_FILENAME, \
ET_FUNCTION, \
ET_LINE, \
_format, \
##__VA_ARGS__); \
} \
} while (0)
#define ET_CHECK_OR_LOG_ERROR(_condition, _format, ...) \
do { \
if (!(_condition)) { \
ET_LOG(Error, _format, ##__VA_ARGS__); \
} \
} while (0)
#else
#define ET_LOG(_level, _format, ...) ((void)0)
#define ET_CHECK_OR_LOG_ERROR(_condition, _format, ...) ((void)0)
#endif