Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 0 additions & 114 deletions src/native/clr/include/shared/log_types.hh
Original file line number Diff line number Diff line change
@@ -1,119 +1,5 @@
#pragma once

#include <cstdint>
#include <format>
#include <string>
#include <string_view>

#include <shared/log_functions.hh>

// We redeclare macros here
#if defined(log_debug)
#undef log_debug
#endif

#if defined(log_info)
#undef log_info
#endif

#define DO_LOG_FMT(_level, _category_, _fmt_, ...) \
do { \
if ((log_categories & ((_category_))) != 0) { \
::log_ ## _level ## _nocheck_fmt ((_category_), _fmt_ __VA_OPT__(,) __VA_ARGS__); \
} \
} while (0)

//
// For std::format spec, see https://en.cppreference.com/w/cpp/utility/format/spec
//

// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style
#define log_debug(_category_, _fmt_, ...) DO_LOG_FMT (debug, (_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__)

// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style
#define log_info(_category_, _fmt_, ...) DO_LOG_FMT (info, (_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__)

// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style
#define log_warn(_category_, _fmt_, ...) log_warn_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__)

// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style
#define log_error(_category_, _fmt_, ...) log_error_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__)

// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style
#define log_fatal(_category_, _fmt_, ...) log_fatal_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__)

namespace xamarin::android {
[[gnu::always_inline]]
static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept
{
log_write (category, level, message.data ());
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_write_fmt (LogCategories category, LogLevel level, std::format_string<Args...> fmt, Args&& ...args)
{
log_write (category, level, std::format (fmt, std::forward<Args>(args)...).c_str ());
}
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_debug_nocheck_fmt (LogCategories category, std::format_string<Args...> fmt, Args&& ...args)
{
log_write (category, xamarin::android::LogLevel::Debug, std::format (fmt, std::forward<Args>(args)...).c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_debug_nocheck (LogCategories category, std::string_view const& message) noexcept
{
log_write (category, xamarin::android::LogLevel::Debug, message.data ());
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_info_nocheck_fmt (LogCategories category, std::format_string<Args...> fmt, Args&& ...args)
{
log_write (category, xamarin::android::LogLevel::Info, std::format (fmt, std::forward<Args>(args)...).c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_info_nocheck (LogCategories category, std::string_view const& message) noexcept
{
log_write (category, xamarin::android::LogLevel::Info, message.data ());
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_warn_fmt (LogCategories category, std::format_string<Args...> fmt, Args&& ...args) noexcept
{
log_write (category, xamarin::android::LogLevel::Warn, std::format (fmt, std::forward<Args>(args)...).c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_warn_fmt (LogCategories category, std::string_view const& message) noexcept
{
log_write (category, xamarin::android::LogLevel::Warn, message.data ());
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_error_fmt (LogCategories category, std::format_string<Args...> fmt, Args&& ...args) noexcept
{
log_write (category, xamarin::android::LogLevel::Error, std::format (fmt, std::forward<Args>(args)...).c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_error_fmt (LogCategories category, std::string_view const& message) noexcept
{
log_write (category, xamarin::android::LogLevel::Error, message.data ());
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_fatal_fmt (LogCategories category, std::format_string<Args...> fmt, Args&& ...args) noexcept
{
log_write (category, xamarin::android::LogLevel::Fatal, std::format (fmt, std::forward<Args>(args)...).c_str ());
}

[[gnu::always_inline]]
static inline constexpr void log_fatal_fmt (LogCategories category, std::string_view const& message) noexcept
{
log_write (category, xamarin::android::LogLevel::Fatal, message.data ());
}

extern unsigned int log_categories;
9 changes: 9 additions & 0 deletions src/native/common/include/shared/log_functions.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdarg>
#include <string_view>

#include "java-interop-logger.h"
#include <shared/log_level.hh>
Expand All @@ -15,4 +16,12 @@ namespace xamarin::android {
void log_infof (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3)));
void log_warnf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3)));
void log_errorf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3)));

// `message` must be a NUL-terminated string, `std::string_view` is used here merely to avoid
// having to call `.data ()` at every call site that uses a string literal.
[[gnu::always_inline]]
static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept
{
Comment on lines +20 to +24
log_write (category, level, message.data ());
}
}
8 changes: 0 additions & 8 deletions src/native/mono/shared/log_types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
// NOTE: _fmt_ takes arguments in the std::format style not the POSIX printf style
#define log_fatal(_category_, _fmt_, ...) log_fatal_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__)

namespace xamarin::android {
[[gnu::always_inline]]
static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept
{
log_write (category, level, message.data ());
}
}

template<typename ...Args> [[gnu::always_inline]]
static inline constexpr void log_debug_nocheck_fmt (LogCategories category, std::format_string<Args...> fmt, Args&& ...args)
{
Expand Down
Loading