2024-01-11 08:08:16 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
2023-12-22 11:57:49 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0+
|
2009-07-03 00:49:40 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
#include "Pcsx2Defs.h"
|
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
#include "fmt/core.h"
|
|
|
|
|
|
|
|
#include <cstdarg>
|
2022-05-18 13:27:23 +00:00
|
|
|
#include <string>
|
2021-09-06 18:28:26 +00:00
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
// TODO: This whole thing needs to get ripped out.
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
enum ConsoleColors
|
|
|
|
{
|
|
|
|
Color_Default = 0,
|
|
|
|
|
|
|
|
Color_Black,
|
|
|
|
Color_Green,
|
|
|
|
Color_Red,
|
|
|
|
Color_Blue,
|
|
|
|
Color_Magenta,
|
|
|
|
Color_Orange,
|
|
|
|
Color_Gray,
|
|
|
|
|
|
|
|
Color_Cyan, // faint visibility, intended for logging PS2/IOP output
|
|
|
|
Color_Yellow, // faint visibility, intended for logging PS2/IOP output
|
|
|
|
Color_White, // faint visibility, intended for logging PS2/IOP output
|
|
|
|
|
|
|
|
// Strong text *may* result in mis-aligned text in the console, depending on the
|
|
|
|
// font and the platform, so use these with caution.
|
|
|
|
Color_StrongBlack,
|
|
|
|
Color_StrongRed, // intended for errors
|
|
|
|
Color_StrongGreen, // intended for infrequent state information
|
|
|
|
Color_StrongBlue, // intended for block headings
|
|
|
|
Color_StrongMagenta,
|
|
|
|
Color_StrongOrange, // intended for warnings
|
|
|
|
Color_StrongGray,
|
|
|
|
|
|
|
|
Color_StrongCyan,
|
|
|
|
Color_StrongYellow,
|
|
|
|
Color_StrongWhite,
|
|
|
|
|
|
|
|
ConsoleColors_Count
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
};
|
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
enum LOGLEVEL
|
2009-07-03 00:49:40 +00:00
|
|
|
{
|
2024-01-11 08:08:16 +00:00
|
|
|
LOGLEVEL_NONE, // Silences all log traffic
|
|
|
|
LOGLEVEL_ERROR,
|
|
|
|
LOGLEVEL_WARNING,
|
|
|
|
LOGLEVEL_INFO,
|
|
|
|
LOGLEVEL_DEV,
|
|
|
|
LOGLEVEL_DEBUG,
|
|
|
|
LOGLEVEL_TRACE,
|
|
|
|
|
|
|
|
LOGLEVEL_COUNT,
|
2009-11-15 06:26:55 +00:00
|
|
|
};
|
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
// TODO: Move this elsewhere, add channels.
|
2009-11-15 06:26:55 +00:00
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
namespace Log
|
2009-11-15 06:26:55 +00:00
|
|
|
{
|
2024-01-11 08:08:16 +00:00
|
|
|
// log message callback type
|
|
|
|
using HostCallbackType = void (*)(LOGLEVEL level, ConsoleColors color, std::string_view message);
|
|
|
|
|
|
|
|
// returns the time in seconds since the start of the process
|
|
|
|
float GetCurrentMessageTime();
|
|
|
|
|
|
|
|
// adds a standard console output
|
|
|
|
bool IsConsoleOutputEnabled();
|
|
|
|
void SetConsoleOutputLevel(LOGLEVEL level);
|
|
|
|
|
|
|
|
// adds a debug console output
|
2024-01-12 15:19:51 +00:00
|
|
|
bool IsDebugOutputAvailable();
|
2024-01-11 08:08:16 +00:00
|
|
|
bool IsDebugOutputEnabled();
|
|
|
|
void SetDebugOutputLevel(LOGLEVEL level);
|
|
|
|
|
|
|
|
// adds a file output
|
|
|
|
bool IsFileOutputEnabled();
|
|
|
|
bool SetFileOutputLevel(LOGLEVEL level, std::string path);
|
|
|
|
|
|
|
|
// returns the log file, this is really dangerous to use if it changes...
|
|
|
|
std::FILE* GetFileLogHandle();
|
|
|
|
|
|
|
|
// adds host output
|
|
|
|
bool IsHostOutputEnabled();
|
|
|
|
void SetHostOutputLevel(LOGLEVEL level, HostCallbackType callback);
|
|
|
|
|
|
|
|
// sets logging timestamps
|
|
|
|
bool AreTimestampsEnabled();
|
|
|
|
void SetTimestampsEnabled(bool enabled);
|
|
|
|
|
|
|
|
// Returns the current global filtering level.
|
|
|
|
LOGLEVEL GetMaxLevel();
|
|
|
|
|
|
|
|
// writes a message to the log
|
|
|
|
void Write(LOGLEVEL level, ConsoleColors color, std::string_view message);
|
|
|
|
void Writef(LOGLEVEL level, ConsoleColors color, const char* format, ...);
|
|
|
|
void Writev(LOGLEVEL level, ConsoleColors color, const char* format, va_list ap);
|
|
|
|
void WriteFmtArgs(LOGLEVEL level, ConsoleColors color, fmt::string_view fmt, fmt::format_args args);
|
|
|
|
|
|
|
|
template <typename... T>
|
|
|
|
__fi static void Write(LOGLEVEL level, ConsoleColors color, fmt::format_string<T...> fmt, T&&... args)
|
|
|
|
{
|
|
|
|
// Avoid arg packing if filtered.
|
|
|
|
if (level <= GetMaxLevel())
|
|
|
|
return WriteFmtArgs(level, color, fmt, fmt::make_format_args(args...));
|
|
|
|
}
|
|
|
|
} // namespace Log
|
|
|
|
|
|
|
|
// Adapter classes to handle old code.
|
|
|
|
template <LOGLEVEL level>
|
|
|
|
struct ConsoleLogWriter
|
2009-11-15 06:26:55 +00:00
|
|
|
{
|
2024-01-11 08:08:16 +00:00
|
|
|
__fi static void Error(std::string_view str) { Log::Write(level, Color_StrongRed, str); }
|
|
|
|
__fi static void Warning(std::string_view str) { Log::Write(level, Color_StrongOrange, str); }
|
|
|
|
__fi static void WriteLn(std::string_view str) { Log::Write(level, Color_Default, str); }
|
|
|
|
__fi static void WriteLn(ConsoleColors color, std::string_view str) { Log::Write(level, color, str); }
|
|
|
|
__fi static void WriteLn() { Log::Write(level, Color_Default, std::string_view()); }
|
|
|
|
__fi static void FormatV(const char* format, va_list ap) { Log::Writev(level, Color_Default, format, ap); }
|
|
|
|
__fi static void FormatV(ConsoleColors color, const char* format, va_list ap) { Log::Writev(level, color, format, ap); }
|
|
|
|
|
|
|
|
#define MAKE_PRINTF_CONSOLE_WRITER(color) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
std::va_list ap; \
|
|
|
|
va_start(ap, format); \
|
|
|
|
Log::Writev(level, color, format, ap); \
|
|
|
|
va_end(ap); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
// clang-format off
|
2024-03-18 00:02:46 +00:00
|
|
|
static void Error(const char* format, ...) { MAKE_PRINTF_CONSOLE_WRITER(Color_StrongRed); }
|
|
|
|
static void Warning(const char* format, ...) { MAKE_PRINTF_CONSOLE_WRITER(Color_StrongOrange); }
|
|
|
|
static void WriteLn(const char* format, ...) { MAKE_PRINTF_CONSOLE_WRITER(Color_Default); }
|
|
|
|
static void WriteLn(ConsoleColors color, const char* format, ...) { MAKE_PRINTF_CONSOLE_WRITER(color); }
|
2024-01-11 08:08:16 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
#undef MAKE_PRINTF_CONSOLE_WRITER
|
|
|
|
|
|
|
|
#define MAKE_FMT_CONSOLE_WRITER(color) do \
|
|
|
|
{ \
|
|
|
|
if (level <= Log::GetMaxLevel()) \
|
|
|
|
Log::WriteFmtArgs(level, color, fmt, fmt::make_format_args(args...)); \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
template<typename... T> __fi static void ErrorFmt(fmt::format_string<T...> fmt, T&&... args) { MAKE_FMT_CONSOLE_WRITER(Color_StrongRed); }
|
|
|
|
template<typename... T> __fi static void WarningFmt(fmt::format_string<T...> fmt, T&&... args) { MAKE_FMT_CONSOLE_WRITER(Color_StrongOrange); }
|
|
|
|
template<typename... T> __fi static void WriteLnFmt(fmt::format_string<T...> fmt, T&&... args) { MAKE_FMT_CONSOLE_WRITER(Color_Default); }
|
|
|
|
template<typename... T> __fi static void WriteLnFmt(ConsoleColors color, fmt::format_string<T...> fmt, T&&... args) { MAKE_FMT_CONSOLE_WRITER(color); }
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
#undef MAKE_FMT_CONSOLE_WRITER
|
2009-11-15 06:26:55 +00:00
|
|
|
};
|
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
struct NullLogWriter
|
2009-11-15 06:26:55 +00:00
|
|
|
{
|
2024-01-11 08:08:16 +00:00
|
|
|
// clang-format off
|
|
|
|
__fi static bool Error(std::string_view str) { return false; }
|
|
|
|
__fi static bool Warning(std::string_view str) { return false; }
|
|
|
|
__fi static bool WriteLn(std::string_view str) { return false; }
|
|
|
|
__fi static bool WriteLn(ConsoleColors color, std::string_view str) { return false; }
|
|
|
|
__fi static bool WriteLn() { return false; }
|
|
|
|
|
|
|
|
__fi static bool Error(const char* format, ...) { return false; }
|
|
|
|
__fi static bool Warning(const char* format, ...) { return false; }
|
|
|
|
__fi static bool WriteLn(const char* format, ...) { return false; }
|
|
|
|
__fi static bool WriteLn(ConsoleColors color, const char* format, ...) { return false; }
|
|
|
|
|
|
|
|
template<typename... T> __fi static bool ErrorFmt(fmt::format_string<T...> fmt, T&&... args) { return false; }
|
|
|
|
template<typename... T> __fi static bool WarningFmt(fmt::format_string<T...> fmt, T&&... args) { return false; }
|
|
|
|
template<typename... T> __fi static bool WriteLnFmt(fmt::format_string<T...> fmt, T&&... args) { return false; }
|
|
|
|
template<typename... T> __fi static bool WriteLnFmt(ConsoleColors color, fmt::format_string<T...> fmt, T&&... args) { return false; }
|
|
|
|
// clang-format on
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
};
|
2009-07-03 00:49:40 +00:00
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
extern ConsoleLogWriter<LOGLEVEL_INFO> Console;
|
|
|
|
extern ConsoleLogWriter<LOGLEVEL_DEV> DevCon;
|
2009-07-03 00:49:40 +00:00
|
|
|
|
2024-01-11 08:08:16 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
extern ConsoleLogWriter<LOGLEVEL_DEBUG> DbgConWriter;
|
2016-11-12 15:28:37 +00:00
|
|
|
#define DbgCon DbgConWriter
|
2009-07-03 00:49:40 +00:00
|
|
|
#else
|
2024-01-11 08:08:16 +00:00
|
|
|
extern NullLogWriter DbgConWriter;
|
|
|
|
#define DbgCon 0 && DbgConWriter
|
2009-07-03 00:49:40 +00:00
|
|
|
#endif
|