2007-03-23 22:26:35 +00:00
|
|
|
/*
|
|
|
|
AppleWin : An Apple //e emulator for Windows
|
|
|
|
|
|
|
|
Copyright (C) 1994-1996, Michael O'Brien
|
|
|
|
Copyright (C) 1999-2001, Oliver Schmidt
|
|
|
|
Copyright (C) 2002-2005, Tom Charlesworth
|
2007-04-01 15:24:52 +00:00
|
|
|
Copyright (C) 2006-2007, Tom Charlesworth, Michael Pohoreski, Nick Westgate
|
2007-03-23 22:26:35 +00:00
|
|
|
|
|
|
|
AppleWin 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; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
AppleWin 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 for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with AppleWin; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Description: Log
|
|
|
|
*
|
|
|
|
* Author: Nick Westgate
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
2010-02-14 21:11:26 +00:00
|
|
|
|
2020-11-11 21:15:27 +00:00
|
|
|
#include "Log.h"
|
2022-02-13 21:37:05 +00:00
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
2018-04-08 16:37:26 +00:00
|
|
|
FILE* g_fh = NULL;
|
2007-03-23 22:26:35 +00:00
|
|
|
|
2020-12-29 21:13:35 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define LOG_FILENAME "AppleWin.log"
|
|
|
|
#else
|
|
|
|
// save to /tmp as otherwise it creates a file in the current folder which can be a bit everywhere
|
|
|
|
// especially if the program is installed to /usr
|
|
|
|
#define LOG_FILENAME "/tmp/AppleWin.log"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-03-23 22:26:35 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-02-13 21:37:05 +00:00
|
|
|
inline std::string GetTimeStamp()
|
|
|
|
{
|
|
|
|
time_t ltime;
|
|
|
|
time(<ime);
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
char ct[32];
|
|
|
|
ctime_s(ct, sizeof(ct), <ime);
|
|
|
|
#else
|
|
|
|
char ctbuf[32];
|
|
|
|
const char* ct = ctime_r(<ime, ctbuf);
|
|
|
|
#endif
|
|
|
|
return std::string(ct, 24);
|
|
|
|
}
|
|
|
|
|
2018-07-15 14:38:37 +00:00
|
|
|
void LogInit(void)
|
|
|
|
{
|
|
|
|
if (g_fh)
|
|
|
|
return;
|
|
|
|
|
2020-12-29 21:13:35 +00:00
|
|
|
g_fh = fopen(LOG_FILENAME, "a+t"); // Open log file (append & text mode)
|
2021-04-23 19:49:31 +00:00
|
|
|
if (!g_fh)
|
|
|
|
{
|
|
|
|
LogOutput("Failed to open logfile '%s'\n", LOG_FILENAME);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-15 14:38:37 +00:00
|
|
|
setvbuf(g_fh, NULL, _IONBF, 0); // No buffering (so implicit fflush after every fprintf)
|
2022-02-13 21:37:05 +00:00
|
|
|
|
|
|
|
fprintf(g_fh, "*** Logging started: %s\n", GetTimeStamp().c_str());
|
2018-07-15 14:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogDone(void)
|
|
|
|
{
|
|
|
|
if (!g_fh)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(g_fh,"*** Logging ended\n\n");
|
|
|
|
fclose(g_fh);
|
|
|
|
g_fh = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-02-13 21:37:05 +00:00
|
|
|
void LogOutput(const char* format, ...)
|
2007-03-23 22:26:35 +00:00
|
|
|
{
|
2015-07-30 16:21:31 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2007-03-23 22:26:35 +00:00
|
|
|
|
2022-02-26 18:39:39 +00:00
|
|
|
OutputDebugString(StrFormatV(format, args).c_str());
|
2022-02-13 21:37:05 +00:00
|
|
|
|
|
|
|
va_end(args);
|
2007-03-23 22:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2013-03-18 23:17:18 +00:00
|
|
|
|
2022-02-13 21:37:05 +00:00
|
|
|
void LogFileOutput(const char* format, ...)
|
2013-03-18 23:17:18 +00:00
|
|
|
{
|
|
|
|
if (!g_fh)
|
|
|
|
return;
|
|
|
|
|
2015-07-30 16:21:31 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2013-03-18 23:17:18 +00:00
|
|
|
|
2022-02-13 21:37:05 +00:00
|
|
|
vfprintf(g_fh, format, args);
|
|
|
|
|
|
|
|
va_end(args);
|
2013-03-18 23:17:18 +00:00
|
|
|
}
|