// license:BSD-3-Clause
// copyright-holders:Vas Crabb
// This file is part of the MAME project (https://www.mamedev.org/).
// Adapted for ES40
#if defined(MAME_EMU_LOGMACRO_H) || !defined(__EMU_H__)
#ifndef _WIN32
#error This file should only be included once per compilation unit after all other headers
#endif
#endif
#define MAME_EMU_LOGMACRO_H

#ifndef VERBOSE
#define VERBOSE 0
#endif

inline void logerror(const char* fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  std::vprintf(fmt, ap);
  va_end(ap);
}

#ifndef LOG_OUTPUT_FUNC
#ifdef LOG_OUTPUT_STREAM
#define LOG_OUTPUT_FUNC [] (auto &&... args) { util::stream_format((LOG_OUTPUT_STREAM), std::forward<decltype(args)>(args)...); }
#else
#define LOG_OUTPUT_FUNC logerror
#endif
#endif

#ifndef LOG_GENERAL
#define LOG_GENERAL (1U << 0)
#endif

#define LOGMASKED(mask, ...) do { if constexpr (VERBOSE & (mask)) (LOG_OUTPUT_FUNC)(__VA_ARGS__); } while (false)

#define LOG(...) LOGMASKED(LOG_GENERAL, __VA_ARGS__)
