2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 /*========================================================================*/
12 * @file CicoSysConLogConfig.cpp
14 * @brief This file implementation of CicoSysConLogConfig class
16 /*========================================================================*/
18 #include <boost/property_tree/ptree.hpp>
19 #include <boost/property_tree/xml_parser.hpp>
20 #include <boost/foreach.hpp>
21 #include <boost/lexical_cast.hpp>
23 using namespace boost;
24 using namespace boost::property_tree;
26 #include "CicoSysConLogConfig.h"
28 //==========================================================================
29 // private static variable
30 //==========================================================================
31 CicoSysConLogConfig* CicoSysConLogConfig::ms_myInstance = NULL;
33 //--------------------------------------------------------------------------
35 * @brief default constructor
37 //--------------------------------------------------------------------------
38 CicoSysConLogConfig::CicoSysConLogConfig()
39 : m_confFile(""), m_name("IcoSysConDaemon"),
40 m_levelPRF(false), m_levelTRA(false), m_levelDBG(false),
41 m_levelINF(false), m_levelWRN(false), m_levelCRI(false),
42 m_levelERR(false), m_flush(false), m_ecore(false)
46 //--------------------------------------------------------------------------
50 //--------------------------------------------------------------------------
51 CicoSysConLogConfig::~CicoSysConLogConfig()
55 //--------------------------------------------------------------------------
57 * @brief Get instance of CicoSysConLogConfig
59 * @return pointer of CicoSysConLogConfig object
61 //--------------------------------------------------------------------------
63 CicoSysConLogConfig::getInstance(void)
65 if (NULL == ms_myInstance) {
66 ms_myInstance = new CicoSysConLogConfig();
71 //--------------------------------------------------------------------------
73 * @brief Get instance of CicoSysConLogConfig
75 * @param [in] confFile config file name
76 * @return 0 on success, other on error
78 //--------------------------------------------------------------------------
80 CicoSysConLogConfig::load(const std::string & confFile)
82 // load xml config file
84 read_xml(confFile, root);
87 if (root.not_found() != root.find("system-controller.log")) {
88 printf("log element not found");
92 ptree log = root.get_child("system-controller.log");
95 optional<std::string> sValue;
96 optional<bool> bValue;
98 // read <performance eneble="xxx"/>
99 sValue = log.get_optional<std::string>("name");
100 if (true == sValue.is_initialized()) {
101 m_name = sValue.get();
104 // read <performance eneble="xxx"/>
105 child = log.get_child("level.performance");
106 bValue = child.get_optional<bool>("<xmlattr>.enable");
107 if (true == bValue.is_initialized()) {
108 m_levelPRF = bValue.get();
111 // read <trace eneble="xxx"/>
112 child = log.get_child("level.trace");
113 bValue = child.get_optional<bool>("<xmlattr>.enable");
114 if (true == bValue.is_initialized()) {
115 m_levelTRA = bValue.get();
118 // read <debug eneble="xxx"/>
119 child = log.get_child("level.debug");
120 bValue = child.get_optional<bool>("<xmlattr>.enable");
121 if (true == bValue.is_initialized()) {
122 m_levelDBG = bValue.get();
125 // read <info eneble="xxx"/>
126 child = log.get_child("level.info");
127 bValue = child.get_optional<bool>("<xmlattr>.enable");
128 if (true == bValue.is_initialized()) {
129 m_levelINF = bValue.get();
132 // read <warning eneble="xxx"/>
133 child = log.get_child("level.warning");
134 bValue = child.get_optional<bool>("<xmlattr>.enable");
135 if (true == bValue.is_initialized()) {
136 m_levelWRN = bValue.get();
139 // read <critical eneble="xxx"/>
140 child = log.get_child("level.critical");
141 bValue = child.get_optional<bool>("<xmlattr>.enable");
142 if (true == bValue.is_initialized()) {
143 m_levelCRI = bValue.get();
146 // read <error eneble="xxx"/>
147 child = log.get_child("level.error");
148 bValue = child.get_optional<bool>("<xmlattr>.enable");
149 if (true == bValue.is_initialized()) {
150 m_levelERR = bValue.get();
153 // read <flush eneble="xxx"/>
154 child = log.get_child("flush");
155 bValue = child.get_optional<bool>("<xmlattr>.enable");
156 if (true == bValue.is_initialized()) {
157 m_flush = bValue.get();
160 // read <ecore eneble="xxx"/>
161 child = log.get_child("ecore");
162 bValue = child.get_optional<bool>("<xmlattr>.enable");
163 if (true == bValue.is_initialized()) {
164 m_ecore = bValue.get();
171 //--------------------------------------------------------------------------
173 * @brief get log name
175 //--------------------------------------------------------------------------
177 CicoSysConLogConfig::getLogName(void)
182 //--------------------------------------------------------------------------
184 * @brief get performance level enable state
186 //--------------------------------------------------------------------------
188 CicoSysConLogConfig::isPRF(void)
193 //--------------------------------------------------------------------------
195 * @brief get trace level enable state
197 //--------------------------------------------------------------------------
199 CicoSysConLogConfig::isTRA(void)
204 //--------------------------------------------------------------------------
206 * @brief get debug level enable state
208 //--------------------------------------------------------------------------
210 CicoSysConLogConfig::isDBG(void)
215 //--------------------------------------------------------------------------
217 * @brief get info level enable state
219 //--------------------------------------------------------------------------
221 CicoSysConLogConfig::isINF(void)
226 //--------------------------------------------------------------------------
228 * @brief get warning level enable state
230 //--------------------------------------------------------------------------
232 CicoSysConLogConfig::isWRN(void)
237 //--------------------------------------------------------------------------
239 * @brief get critical level enable state
241 //--------------------------------------------------------------------------
243 CicoSysConLogConfig::isCRI(void)
248 //--------------------------------------------------------------------------
250 * @brief get error level enable state
252 //--------------------------------------------------------------------------
254 CicoSysConLogConfig::isERR(void)
259 //--------------------------------------------------------------------------
261 * @brief get flush log enable state
263 //--------------------------------------------------------------------------
265 CicoSysConLogConfig::isFlush(void)
270 //--------------------------------------------------------------------------
272 * @brief get ecore log print enalbe state
274 //--------------------------------------------------------------------------
276 CicoSysConLogConfig::isEcore(void)
280 // vim:set expandtab ts=4 sw=4: