Blame view

server/kernel/src/Application/ApplicationLogger.cpp 1.49 KB
346b85c6   Benjamin Renard   First commit with...
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
#include "ApplicationLogger.h"

#include <iostream>
#include <fstream>

#include "Application.h"
#include "../Common/Toolbox.h"

#include "log4cxx/propertyconfigurator.h"
#include "log4cxx/fileappender.h"

using namespace TREPS::Common;

namespace TREPS
{
	namespace Application
	{
		ApplicationLoggerClass::ApplicationLoggerClass(void) : logger(0)
		{
		}

		bool ApplicationLoggerClass::load(void)
		{
			//get logger config file
			ApplicationClass *app = ApplicationClass::getInstance();

			string logPath = app->getConf()->getLog4cxxConfigPath();

			fstream confFile(logPath.c_str(), fstream::in);
			
			if (!confFile.good())
			{
				cerr << "Cannot load logger configuration file : " << logPath << endl;
				return false;
			}
			
			confFile.close();
		
			//Init log4cxx logger
			PropertyConfigurator::configure(logPath.c_str());

			this->logger = Logger::getLogger(app->getConf()->getLog4cxxLoggerName());

			LOG4CXX_INFO(this->logger, "Load logger configuration file : " << logPath);
			
			return true;
		}

		void ApplicationLoggerClass::setLogPath(const char *logPath)
		{
			helpers::Pool p;

			//change the path of the log file
			FileAppenderPtr fileAppender = this->logger->getLoggerRepository()->getRootLogger()->getAppender("F");
			if(fileAppender!= NULL)
			{
				LOG4CXX_INFO(this->logger, "Modify log file to : " << logPath);
				fileAppender->setFile(logPath);
				fileAppender->activateOptions(p);
			}
		}

		LoggerPtr ApplicationLoggerClass::getPtr(void)
		{
			return this->logger;
		}	
	}
}