Scheaven
2021-07-23 3f0ae58275718c03f99799182e40e9429334aac8
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
#include "log_util.h"
#include <sstream>
#include <memory>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <iostream>
 
#include <log4cplus/logger.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/fileappender.h>
#include <log4cplus/configurator.h>
 
using namespace std;
using namespace log4cplus;
 
static Logger global_pLogger;
CLog* CLog::pInstance = NULL;
 
CLog* CLog::Initialize(const string& strLogFile)
{
    if (NULL == pInstance)
    {
        pInstance = new CLog(strLogFile);
    }
    return pInstance;
}
 
CLog::CLog(const string& strLogFile)
{
    PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT(strLogFile));
    global_pLogger = Logger::getRoot();
}
 
void DEBUG_LOG(const string& strInfo, const string& strFile, int iLine)
{
    stringstream ssLogData;
    ssLogData << "[" << strFile << ":" << iLine << "] " << strInfo;
    std::cout << ssLogData.str() << std::endl;
 
 
    LOG4CPLUS_DEBUG(global_pLogger, ssLogData.str());
}
 
void ERROR_LOG(const string& strInfo, const string& strFile, int iLine)
{
    stringstream ssLogData;
    ssLogData << "[" << strFile << ":" << iLine << "] " << strInfo;
    std::cout << ssLogData.str() << std::endl;
    LOG4CPLUS_ERROR(global_pLogger, ssLogData.str());
}
 
void WARN_LOG(const string& strInfo, const string& strFile, int iLine)
{
    stringstream ssLogData;
    ssLogData << "[" << strFile << ":" << iLine << "] " << strInfo;
    std::cout << ssLogData.str() << std::endl;
    LOG4CPLUS_WARN(global_pLogger, ssLogData.str());
}