Commit 2413d6d6 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils (trunk) :
- Move formatDate(...) from LoggerMessage class to StringUtils class.
- Update LoggerManager : now it creates one log file / day.
- Update logger properties.
parent 1569c977
......@@ -34,7 +34,7 @@ namespace ElemUtils {
const std::string ENABLE_NAME = "enable";
const std::string DEFAULT_LEVEL_NAME = "default.level";
const std::string PRINT_MODE_NAME = "print.mode";
const std::string OUTPUT_LOG_FILE_PATH = "log.file.path";
const std::string LOG_FOLDER_PATH = "log.folder.path";
/**
* @class LoggerManager
......
......@@ -9,6 +9,7 @@
*/
#include <stddef.h>
#include <ctime>
#include <string>
#include <utility>
#include <vector>
......@@ -124,8 +125,11 @@ public:
* @param startIndex
* @return
*/
static size_t findFirst(const std::string &file,
const std::string &pattern, const size_t startIndex = 0);
static size_t findFirst(const std::string &file, const std::string &pattern,
const size_t startIndex = 0);
static std::string formatDate(const time_t &time,
const std::string &format);
};
} // namespace ElemUtils
......
......@@ -3,6 +3,7 @@
#include <SFML/System/Lock.hpp>
#include <SFML/System/Sleep.hpp>
#include <SFML/System/Time.hpp>
#include <ctime>
#include <utility>
#include <vector>
......@@ -29,9 +30,11 @@ LoggerManager* LoggerManager::getInstance() {
//TODO remplacer le nom de la propriété "log.file.path" par un static final string
LoggerManager::LoggerManager() :
Thread(), m_outputFilePath("default.log"), m_defaultLevel(
Thread(), m_outputFilePath(StringUtils::EMPTY), m_defaultLevel(
LoggerLevel::INFO), m_printMode(LoggerPrintMode::COUT), m_active(
true) {
m_outputFilePath = ElemUtils::Formatter()
<< StringUtils::formatDate(time(0), "%d-%m-%Y") << "_partons.log";
}
LoggerManager::~LoggerManager() {
......@@ -94,10 +97,11 @@ void LoggerManager::parseConfigurationFile(const std::string &filePath) {
else if (StringUtils::equalsIgnoreCase(it->first, PRINT_MODE_NAME)) {
m_printMode = LoggerPrintMode::fromString(it->second);
}
// retrieve path for log file
else if (StringUtils::equalsIgnoreCase(it->first,
OUTPUT_LOG_FILE_PATH)) {
m_outputFilePath = (it->second);
// retrieve log folder path
else if (StringUtils::equalsIgnoreCase(it->first, LOG_FOLDER_PATH)) {
m_outputFilePath = Formatter() << (it->second) << "/"
<< m_outputFilePath;
debug("LoggerManager", __func__, m_outputFilePath);
}
// handle custom level
else {
......
......@@ -2,6 +2,8 @@
#include <sstream>
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h"
namespace ElemUtils {
LoggerMessage::LoggerMessage(LoggerLevel level, std::string classNameSource,
......@@ -55,24 +57,11 @@ void LoggerMessage::setLevel(LoggerLevel level) {
m_level = level;
}
std::string LoggerMessage::formatDate(const time_t &time) const {
// see : http://stackoverflow.com/questions/16357999/current-date-and-time-as-string
struct tm* timeinfo;
char buffer[80];
timeinfo = localtime(&time);
strftime(buffer, 80, "%d-%m-%Y %I:%M:%S", timeinfo);
return std::string(buffer);
}
std::string LoggerMessage::toString() const {
std::stringstream sstream;
sstream << formatDate(m_time) << " [" << m_level.toString() << "] ("
<< m_classNameSource << "::" << m_functionNameSource << ") "
<< m_message;
sstream << StringUtils::formatDate(m_time, "%d-%m-%Y %I:%M:%S") << " [" << m_level.toString()
<< "] (" << m_classNameSource << "::" << m_functionNameSource
<< ") " << m_message;
return sstream.str();
}
......
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h"
#include <algorithm> // pour transform #include <cctype> #include <cstdlib> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include "../../../include/ElementaryUtils/logger/CustomException.h"
#include <algorithm> // pour transform #include <cctype> #include <cstdlib> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include "../../../include/ElementaryUtils/logger/CustomException.h" #include <cctype> #include <iterator>
#include "../../../include/ElementaryUtils/logger/CustomException.h"
#include "../../../include/ElementaryUtils/logger/LoggerManager.h"
#include "../../../include/ElementaryUtils/string_utils/Formatter.h"
......@@ -365,4 +367,17 @@ size_t StringUtils::findFirst(const std::string& file,
return fileSize;
}
std::string StringUtils::formatDate(const time_t &time, const std::string &format) {
// see : http://stackoverflow.com/questions/16357999/current-date-and-time-as-string
struct tm* timeinfo;
char buffer[80];
timeinfo = localtime(&time);
strftime(buffer, 80, format.c_str(), timeinfo);
return std::string(buffer);
}
} // namespace ElemUtils
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment