CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/Log.h
Views: 1401
// Copyright (C) 2003 Dolphin Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official SVN repository and contact information can be found at15// http://code.google.com/p/dolphin-emu/1617#pragma once1819#include "CommonFuncs.h"2021#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and debugprintfs from the game itself.22#define ERROR_LEVEL 2 // Important errors.23#define WARNING_LEVEL 3 // Something is suspicious.24#define INFO_LEVEL 4 // General information.25#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.26#define VERBOSE_LEVEL 6 // Noisy debugging - sometimes needed but usually unimportant.2728// NOTE: Needs to be kept in sync with the g_logTypeNames array.29enum class Log {30System = 0, // Catch-all for uncategorized things31Boot,32Common,33CPU,34FileSystem,35G3D,36HLE, // dumping ground that we should get rid of37JIT,38Loader,39ME,40MemMap,41SasMix,42SaveState,43FrameBuf,44Audio,45IO,46Achievements,47HTTP,48Printf,4950sceAudio,51sceCtrl,52sceDisplay,53sceFont,54sceGe,55sceIntc,56sceIo,57sceKernel,58sceModule,59sceNet,60sceRtc,61sceSas,62sceUtility,63sceMisc,6465NUMBER_OF_LOGS, // Must be last66};6768enum class LogLevel : int {69LNOTICE = NOTICE_LEVEL,70LERROR = ERROR_LEVEL,71LWARNING = WARNING_LEVEL,72LINFO = INFO_LEVEL,73LDEBUG = DEBUG_LEVEL,74LVERBOSE = VERBOSE_LEVEL,75};7677void GenericLog(LogLevel level, Log type, const char *file, int line, const char *fmt, ...)78#ifdef __GNUC__79__attribute__((format(printf, 5, 6)))80#endif81;82bool GenericLogEnabled(LogLevel level, Log type);8384// Exception for Windows - enable more log levels in release mode than on other platforms.85#if defined(_DEBUG) || defined(_WIN32)8687// Needs to be an int (and not use the enum) because it's used by the preprocessor!88#define MAX_LOGLEVEL DEBUG_LEVEL8990#else9192#ifndef MAX_LOGLEVEL93#define MAX_LOGLEVEL INFO_LEVEL94#endif // loglevel9596#endif // logging9798// Let the compiler optimize this out.99// TODO: Compute a dynamic max level as well that can be checked here.100#define GENERIC_LOG(t, v, ...) { \101if ((int)v <= MAX_LOGLEVEL) \102GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \103}104105#define ERROR_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LERROR, __VA_ARGS__) } while (false)106#define WARN_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LWARNING, __VA_ARGS__) } while (false)107#define NOTICE_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LNOTICE, __VA_ARGS__) } while (false)108#define INFO_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LINFO, __VA_ARGS__) } while (false)109#define DEBUG_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LDEBUG, __VA_ARGS__) } while (false)110#define VERBOSE_LOG(t,...) do { GENERIC_LOG(t, LogLevel::LVERBOSE, __VA_ARGS__) } while (false)111112// Currently only actually shows a dialog box on Windows.113bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...)114#ifdef __GNUC__115__attribute__((format(printf, 5, 6)))116#endif117;118119bool HitAnyAsserts();120void ResetHitAnyAsserts();121void SetExtraAssertInfo(const char *info);122void SetCleanExitOnAssert();123124#if defined(__ANDROID__)125// Tricky macro to get the basename, that also works if *built* on Win32.126// Doesn't mean this macro can be used on Win32 though.127#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__))128#else129#define __FILENAME__ __FILE__130#endif131132// If we're a debug build, _dbg_assert_ is active. Not otherwise, even on Windows.133#if defined(_DEBUG)134135#define _dbg_assert_(_a_) \136if (!(_a_)) {\137if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \138}139140#define _dbg_assert_msg_(_a_, ...) \141if (!(_a_)) { \142if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \143}144145#else // not debug146147#ifndef _dbg_assert_148#define _dbg_assert_(_a_) {}149#define _dbg_assert_msg_(_a_, _desc_, ...) {}150#endif // dbg_assert151152#endif // MAX_LOGLEVEL DEBUG153154#define _assert_(_a_) \155if (!(_a_)) {\156if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assert!\n")) Crash(); \157}158159#define _assert_msg_(_a_, ...) \160if (!(_a_)) { \161if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \162}163164// Just INFO_LOGs on nonWindows. On Windows it outputs to the VS output console.165void OutputDebugStringUTF8(const char *p);166167168