project64/Source/Project64-video/TextureEnhancer/TxDbg.cpp

58 lines
1.2 KiB
C++
Raw Normal View History

2021-03-02 02:13:17 +00:00
// Project64 - A Nintendo 64 emulator
// https://www.pj64-emu.com/
2021-03-02 02:13:17 +00:00
// Copyright(C) 2001-2021 Project64
// Copyright(C) 2007 Hiroshi Morii
// Copyright(C) 2003 Rice1964
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
2013-04-17 10:30:38 +00:00
#define DBG_LEVEL 80
#include "TxDbg.h"
#include <string.h>
#include <stdarg.h>
#include <Common/StdString.h>
2013-04-17 10:30:38 +00:00
#include <Common/path.h>
#include <Project64-video/Config.h>
#include <Project64-video/Settings.h>
2013-04-17 10:30:38 +00:00
TxDbg::TxDbg()
{
2017-01-23 21:34:08 +00:00
const char * log_dir = g_settings->log_dir();
2021-04-12 11:35:39 +00:00
if (log_dir != nullptr && log_dir[0] != '\0')
{
2017-01-23 21:34:08 +00:00
_level = DBG_LEVEL;
2017-01-23 21:34:08 +00:00
if (!_dbgfile)
2013-04-17 10:30:38 +00:00
#ifdef GHQCHK
2017-01-23 21:34:08 +00:00
_dbgfile = fopen(CPath(log_dir, "ghqchk.txt"), "w");
2013-04-17 10:30:38 +00:00
#else
2017-01-23 21:34:08 +00:00
_dbgfile = fopen(CPath(log_dir, "glidehq.dbg"), "w");
2013-04-17 10:30:38 +00:00
#endif
2017-01-23 21:34:08 +00:00
}
2013-04-17 10:30:38 +00:00
}
TxDbg::~TxDbg()
{
2017-04-26 10:23:36 +00:00
if (_dbgfile)
2017-01-23 21:34:08 +00:00
{
2016-02-04 17:31:18 +00:00
fclose(_dbgfile);
_dbgfile = 0;
}
2013-04-17 10:30:38 +00:00
2016-02-04 17:31:18 +00:00
_level = DBG_LEVEL;
2013-04-17 10:30:38 +00:00
}
void
TxDbg::output(const int level, const char *format, ...)
2013-04-17 10:30:38 +00:00
{
2016-02-04 17:31:18 +00:00
if (level > _level)
return;
2013-04-17 10:30:38 +00:00
stdstr_f newformat("%d:\t%s", level, format);
2013-04-17 10:30:38 +00:00
2016-02-04 17:31:18 +00:00
va_list args;
va_start(args, format);
vfprintf(_dbgfile, newformat.c_str(), args);
2016-02-04 17:31:18 +00:00
fflush(_dbgfile);
va_end(args);
}