Better parsing of bool properties
parent
f773d5714d
commit
bd10f424ec
|
@ -164,14 +164,7 @@ bool CConfigFile::GetStringProperty(std::string section, std::string key, std::s
|
||||||
}
|
}
|
||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
if (m_loaded)
|
GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s\n", e.what());
|
||||||
{
|
|
||||||
GetLogger()->Info("Error on parsing config file: %s\n", e.what());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GetLogger()->Trace("Error on parsing config file: %s\n", e.what());
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -201,14 +194,7 @@ bool CConfigFile::GetIntProperty(std::string section, std::string key, int &valu
|
||||||
}
|
}
|
||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
if (m_loaded)
|
GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s\n", e.what());
|
||||||
{
|
|
||||||
GetLogger()->Info("Error on parsing config file: %s\n", e.what());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GetLogger()->Trace("Error on parsing config file: %s\n", e.what());
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -225,7 +211,19 @@ bool CConfigFile::GetBoolProperty(std::string section, std::string key, bool& va
|
||||||
bool result = GetIntProperty(section, key, intValue);
|
bool result = GetIntProperty(section, key, intValue);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
value = intValue == 1;
|
if (intValue == 0)
|
||||||
|
{
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
else if (intValue == 1)
|
||||||
|
{
|
||||||
|
value = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing bool property %s.%s (expected 0 or 1, not %d)\n", section, key, intValue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -254,14 +252,7 @@ bool CConfigFile::GetFloatProperty(std::string section, std::string key, float &
|
||||||
}
|
}
|
||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
if (m_loaded)
|
GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s\n", e.what());
|
||||||
{
|
|
||||||
GetLogger()->Info("Error on parsing config file: %s\n", e.what());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GetLogger()->Trace("Error on parsing config file: %s\n", e.what());
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -36,13 +36,11 @@ CLogger::CLogger()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CLogger::~CLogger()
|
CLogger::~CLogger()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Log(LogLevel type, const char* str, va_list args)
|
void CLogger::Log(LogLevel type, const char* str, va_list args)
|
||||||
{
|
{
|
||||||
if (type < m_logLevel)
|
if (type < m_logLevel)
|
||||||
|
@ -72,7 +70,6 @@ void CLogger::Log(LogLevel type, const char* str, va_list args)
|
||||||
vfprintf(IsOpened() ? m_file : stderr, str, args);
|
vfprintf(IsOpened() ? m_file : stderr, str, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Trace(const char* str, ...)
|
void CLogger::Trace(const char* str, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -81,7 +78,6 @@ void CLogger::Trace(const char* str, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Debug(const char* str, ...)
|
void CLogger::Debug(const char* str, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -90,7 +86,6 @@ void CLogger::Debug(const char* str, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Info(const char* str, ...)
|
void CLogger::Info(const char* str, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -99,7 +94,6 @@ void CLogger::Info(const char* str, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Warn(const char* str, ...)
|
void CLogger::Warn(const char* str, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -108,7 +102,6 @@ void CLogger::Warn(const char* str, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Error(const char* str, ...)
|
void CLogger::Error(const char* str, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -117,7 +110,6 @@ void CLogger::Error(const char* str, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Message(const char* str, ...)
|
void CLogger::Message(const char* str, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -126,6 +118,13 @@ void CLogger::Message(const char* str, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CLogger::Log(LogLevel logLevel, const char* str, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, str);
|
||||||
|
Log(logLevel, str, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
void CLogger::SetOutputFile(std::string filename)
|
void CLogger::SetOutputFile(std::string filename)
|
||||||
{
|
{
|
||||||
|
@ -133,7 +132,6 @@ void CLogger::SetOutputFile(std::string filename)
|
||||||
Open();
|
Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Open()
|
void CLogger::Open()
|
||||||
{
|
{
|
||||||
m_file = fopen(m_filename.c_str(), "w");
|
m_file = fopen(m_filename.c_str(), "w");
|
||||||
|
@ -142,26 +140,22 @@ void CLogger::Open()
|
||||||
fprintf(stderr, "Could not create file %s\n", m_filename.c_str());
|
fprintf(stderr, "Could not create file %s\n", m_filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::Close()
|
void CLogger::Close()
|
||||||
{
|
{
|
||||||
if (IsOpened())
|
if (IsOpened())
|
||||||
fclose(m_file);
|
fclose(m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CLogger::IsOpened()
|
bool CLogger::IsOpened()
|
||||||
{
|
{
|
||||||
return m_file != NULL;
|
return m_file != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLogger::SetLogLevel(LogLevel type)
|
void CLogger::SetLogLevel(LogLevel type)
|
||||||
{
|
{
|
||||||
m_logLevel = type;
|
m_logLevel = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CLogger::ParseLogLevel(const std::string& str, LogLevel& logLevel)
|
bool CLogger::ParseLogLevel(const std::string& str, LogLevel& logLevel)
|
||||||
{
|
{
|
||||||
if (str == "trace")
|
if (str == "trace")
|
||||||
|
|
|
@ -96,6 +96,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void Error(const char *str, ...);
|
void Error(const char *str, ...);
|
||||||
|
|
||||||
|
/** Write message to console or file with given log level
|
||||||
|
* \param logLevel - log level
|
||||||
|
* \param str - message to write
|
||||||
|
* \param ... - additional arguments
|
||||||
|
*/
|
||||||
|
void Log(LogLevel logLevel, const char *str, ...);
|
||||||
|
|
||||||
/** Set output file to write logs to
|
/** Set output file to write logs to
|
||||||
* \param filename - output file to write to
|
* \param filename - output file to write to
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue