ppsspp/Common/Log.h

157 lines
4.1 KiB
C
Raw Normal View History

2012-11-01 15:19:01 +00:00
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
2012-11-01 15:19:01 +00:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#pragma once
2012-11-01 15:19:01 +00:00
2014-09-06 08:47:25 +00:00
#include "MsgHandler.h"
#ifdef __arm__
#if !defined(ARM)
#define ARM
#endif
#endif
#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and debugprintfs from the game itself.
#define ERROR_LEVEL 2 // Important errors.
2012-11-01 15:19:01 +00:00
#define WARNING_LEVEL 3 // Something is suspicious.
#define INFO_LEVEL 4 // General information.
#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.
#define VERBOSE_LEVEL 6 // Noisy debugging - sometimes needed but usually unimportant.
2012-11-01 15:19:01 +00:00
#if !defined(_WIN32)
#include <signal.h>
#endif
#include <cstdio>
2012-11-01 15:19:01 +00:00
namespace LogTypes
{
enum LOG_TYPE {
MASTER_LOG,
SCEAUDIO,
SCECTRL,
SCEDISPLAY,
SCEFONT,
SCEGE,
SCEINTC,
SCEIO,
SCEKERNEL,
SCEMODULE,
SCENET,
SCERTC,
SCESAS,
SCEUTILITY,
BOOT,
COMMON,
CPU,
FILESYS,
G3D,
HLE, // dumping ground that we should get rid off
JIT,
LOADER,
ME,
MEMMAP,
TIME,
SASMIX,
NUMBER_OF_LOGS, // Must be last
2012-11-01 15:19:01 +00:00
};
enum LOG_LEVELS {
LNOTICE = NOTICE_LEVEL,
LERROR = ERROR_LEVEL,
LWARNING = WARNING_LEVEL,
LINFO = INFO_LEVEL,
LDEBUG = DEBUG_LEVEL,
LVERBOSE = VERBOSE_LEVEL,
2012-11-01 15:19:01 +00:00
};
} // namespace
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
2012-11-01 15:19:01 +00:00
const char *file, int line, const char *fmt, ...)
#ifdef __GNUC__
__attribute__((format(printf, 5, 6)))
#endif
;
#if defined(LOGGING) || defined(_DEBUG) || defined(DEBUGFAST) || defined(_WIN32)
2012-11-01 15:19:01 +00:00
#define MAX_LOGLEVEL DEBUG_LEVEL
#else
#ifndef MAX_LOGLEVEL
#define MAX_LOGLEVEL INFO_LEVEL
#endif // loglevel
#endif // logging
// Let the compiler optimize this out
#define GENERIC_LOG(t, v, ...) { \
if (v <= MAX_LOGLEVEL) \
GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
}
#define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (false)
#define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (false)
#define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (false)
#define INFO_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) } while (false)
#define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (false)
#define VERBOSE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LVERBOSE, __VA_ARGS__) } while (false)
2012-11-01 15:19:01 +00:00
#if MAX_LOGLEVEL >= DEBUG_LEVEL
#define _dbg_assert_(_t_, _a_) \
if (!(_a_)) {\
ERROR_LOG(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \
__LINE__, __FILE__, __TIME__); \
if (!PanicYesNo("*** Assertion (see log)***\n")) {Crash();} \
}
2014-06-05 06:05:51 +00:00
#ifdef __SYMBIAN32__
#define _dbg_assert_msg_(_t_, _a_, ...) if (!(_a_)) ERROR_LOG(_t_, __VA_ARGS__);
#else
2012-11-01 15:19:01 +00:00
#define _dbg_assert_msg_(_t_, _a_, ...)\
if (!(_a_)) {\
printf(__VA_ARGS__); \
2012-11-01 15:19:01 +00:00
ERROR_LOG(_t_, __VA_ARGS__); \
if (!PanicYesNo(__VA_ARGS__)) {Crash();} \
}
2014-06-05 06:05:51 +00:00
#endif
2012-11-01 15:19:01 +00:00
#define _dbg_update_() ; //Host_UpdateLogDisplay();
#else // not debug
#define _dbg_update_() ;
#ifndef _dbg_assert_
#define _dbg_assert_(_t_, _a_) {}
#define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {}
#endif // dbg_assert
#endif // MAX_LOGLEVEL DEBUG
#define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
#ifdef _MSC_VER
2012-11-01 15:19:01 +00:00
#define _assert_msg_(_t_, _a_, _fmt_, ...) \
if (!(_a_)) {\
if (!PanicYesNo(_fmt_, __VA_ARGS__)) {Crash();} \
}
#else // not win32
#define _assert_msg_(_t_, _a_, _fmt_, ...) \
if (!(_a_)) {\
if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \
}
#endif // WIN32