Files
Client/Server/Billing/Db/Log.cpp
LGram16 dd97ddec92 Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code:
- Client: Game client source (moved to Client/Client/)
- Server: Game server source
- GameTools: Development tools
- CryptoSource: Encryption utilities
- database: Database scripts
- Script: Game scripts
- rylCoder_16.02.2008_src: Legacy coder tools
- GMFont, Game: Additional resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 20:17:20 +09:00

94 lines
1.8 KiB
C++

#include "Log.h"
#include <windows.h>
CLog::CLog()
: m_stdout(0), m_stderr(0)
{
}
CLog::~CLog()
{
if(0 != m_stderr)
{
fclose(m_stderr);
m_stderr = 0;
}
if(0 != m_stdout)
{
fclose(m_stdout);
m_stdout = 0;
}
}
bool CLog::RedirectStdErr(const char* szFileName)
{
char szLogFileName[MAX_PATH];
if(MakeFileName(szFileName, szLogFileName))
{
m_stderr = freopen(szLogFileName, "at", stderr);
return (0 != m_stderr);
}
return false;
}
bool CLog::RedirectStdOut(const char *szFileName)
{
char szLogFileName[MAX_PATH];
if(MakeFileName(szFileName, szLogFileName))
{
m_stdout = freopen(szLogFileName, "at", stdout);
return (0 != m_stdout);
}
return false;
}
bool CLog::MakeFileName(const char* szFileName, char* szLogFileName)
{
// create log file name in good order
for(unsigned long dwSpinCount = 0; TRUE; ++dwSpinCount)
{
int nLength = _snprintf(szLogFileName, MAX_PATH, "%s%04d.log",
szFileName, dwSpinCount);
if(nLength < 0)
{
return false;
}
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(szLogFileName))
{
break;
}
else
{
HANDLE hFile = CreateFile(szLogFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwFileHighSize = 0;
DWORD dwFileSize = GetFileSize(hFile, &dwFileHighSize);
CloseHandle(hFile);
if(0 == dwFileHighSize && dwFileSize < 10 * 1024 * 1024)
{
break;
}
}
}
}
return true;
}