mrDarker
2025-07-16 1dbe46cd9d0f181d08d5a69f72d8548628a13b9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "StdAfx.h"
#include "Edge_Log.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CEdge_Log
 
CEdge_Log::CEdge_Log()
{        
    m_pFileLog = NULL;
    m_strLogPath = _T("");
    m_strLogFile = _T("");    
 
    InitializeCriticalSection(&m_csLog);
}
 
CEdge_Log::~CEdge_Log()
{
    if (m_pFileLog)
    {
        delete m_pFileLog;
        m_pFileLog = NULL;
    }
 
    DeleteCriticalSection(&m_csLog);
}
 
void CEdge_Log::SetPath(CString& strPath, CString& strName, BOOL bDelete, int nRemainCount)
{
    strPath.Replace(_T("/"), _T("\\"));
    CString str = _T("");
    str = strPath.Right(1);
    if (str == _T("\\"))
        m_strLogPath = strPath;
    else
        m_strLogPath = strPath + _T("\\");
    
    m_strLogPath += strName;
 
    MakeLogFile();
}
 
BOOL CEdge_Log::MakeLogFile()
{
    // Log Ã³¸®
    if (m_strLogPath.IsEmpty())
        return FALSE;
 
    m_TimeLogFile = CTime::GetCurrentTime();
    m_strLogFile.Format(_T("%s_%02d_%02d.log"), m_strLogPath, m_TimeLogFile.GetMonth(), m_TimeLogFile.GetDay());
 
    if (m_pFileLog)
        delete m_pFileLog;
 
    m_pFileLog = new CFile();    
 
    return TRUE;
}
 
BOOL CEdge_Log::WriteToFile(CTime& time, CString& strContents)
{
    // ³¯Â¥°¡ ¹Ù²î¸é ÆÄÀϸíÀ» °»½ÅÇØ¼­ ¾´´Ù.
    if ((time.GetMonth() != m_TimeLogFile.GetMonth()) || (time.GetDay() != m_TimeLogFile.GetDay()) || !m_pFileLog)
        MakeLogFile();
 
    if (!m_pFileLog->Open(m_strLogFile, CFile::modeWrite))
    {
        CFileFind filefind;
        if(filefind.FindFile(m_strLogFile) == FALSE)
        {
            if (!m_pFileLog->Open(m_strLogFile, CFile::modeCreate | CFile::modeWrite))
            {
                delete m_pFileLog;
                m_pFileLog = NULL;
            }
        }
 
        filefind.Close();
    }
 
    if (m_pFileLog)
    {
        m_pFileLog->SeekToEnd();
        m_pFileLog->Write(strContents, strContents.GetLength());
        m_pFileLog->Write("\r\n", static_cast<UINT>(strlen("\r\n")));
        m_pFileLog->Close();
    }
 
    return TRUE;
}
 
BOOL CEdge_Log::WriteToFile(CTime& time, char* strContents)
{
    // ³¯Â¥°¡ ¹Ù²î¸é ÆÄÀϸíÀ» °»½ÅÇØ¼­ ¾´´Ù.
    if ((time.GetMonth() != m_TimeLogFile.GetMonth()) || (time.GetDay() != m_TimeLogFile.GetDay()) || !m_pFileLog)
        MakeLogFile();
 
    if (!m_pFileLog->Open(m_strLogFile, CFile::modeWrite))
    {
        CFileFind filefind;
        if(filefind.FindFile(m_strLogFile) == FALSE)
        {
            if (!m_pFileLog->Open(m_strLogFile, CFile::modeCreate | CFile::modeWrite))
            {
                delete m_pFileLog;
                m_pFileLog = NULL;
            }
        }
 
        filefind.Close();
    }
 
    if (m_pFileLog)
    {
        m_pFileLog->SeekToEnd();
        m_pFileLog->Write(strContents, static_cast<UINT>(strlen(strContents)));
        m_pFileLog->Write("\r\n", static_cast<UINT>(strlen("\r\n")));
        m_pFileLog->Close();
    }
 
    return TRUE;
}
 
void CEdge_Log::DisplayEdgeLog(CString str)
{
    try
    {
        EnterCriticalSection(&m_csLog);    
 
        // ÀÔ·ÂÇÒ ¹®ÀÚ¿­ ¸¸µé±â.
        CTime    time = CTime::GetCurrentTime();
        char strTemp[512] = {0, };
        sprintf_s(strTemp, 512, "%02d-%02d-%02d :%s", time.GetHour(), time.GetMinute(), time.GetSecond(), str);
 
        WriteToFile(time, strTemp);    
 
        LeaveCriticalSection(&m_csLog);
    }
    catch (...)
    {
        LeaveCriticalSection(&m_csLog);
        return;
    }
}
 
void CEdge_Log::DisplayEdgeLog(char* str, ...)
{    
    va_list list;
    char strText[256] = {0, };
 
    char strContents[512] = {0,};
    va_start(list, str);
    vsprintf_s(strContents, str, list);
    va_end(list);
 
    
    try
    {
        EnterCriticalSection(&m_csLog);    
 
        // ÀÔ·ÂÇÒ ¹®ÀÚ¿­ ¸¸µé±â.
        CTime    time = CTime::GetCurrentTime();
        char strTemp[512] = {0, };
        sprintf_s(strTemp, 512, "%02d-%02d-%02d :%s", time.GetHour(), time.GetMinute(), time.GetSecond(), strContents);
 
        WriteToFile(time, strTemp);    
 
        LeaveCriticalSection(&m_csLog);
    }
    catch (...)
    {
        LeaveCriticalSection(&m_csLog);
        return;
    }
}