Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:43:50

0001 #ifndef LOGGER_MANAGER_H
0002 #define LOGGER_MANAGER_H
0003 
0004 /**
0005  * @file LoggerManager.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date September 05, 2014
0008  * @version 2.0
0009  */
0010 
0011 #include <SFML/System/Mutex.hpp>
0012 #include <fstream> // needed
0013 #include <iostream>
0014 #include <map>
0015 #include <string>
0016 
0017 #include "../thread/Thread.h"
0018 #include "LoggerClassLevel.h"
0019 #include "LoggerLevel.h"
0020 #include "LoggerPrintMode.h"
0021 
0022 namespace ElemUtils {
0023 class CustomException;
0024 } /* namespace ElemUtils */
0025 
0026 namespace ElemUtils {
0027 class LoggerMessage;
0028 } /* namespace ElemUtils */
0029 
0030 namespace ElemUtils {
0031 
0032 //TODO relatif folder for configFile
0033 
0034 const std::string ENABLE_NAME = "enable";
0035 const std::string DEFAULT_LEVEL_NAME = "default.level";
0036 const std::string PRINT_MODE_NAME = "print.mode";
0037 const std::string LOG_FOLDER_PATH = "log.folder.path";
0038 
0039 /**
0040  * @class LoggerManager
0041  * @brief \<singleton\> Handles logs.
0042  */
0043 class LoggerManager: public Thread {
0044 public:
0045     static LoggerManager* getInstance();
0046 
0047     /**
0048      * Default destructor
0049      */
0050     virtual ~LoggerManager();
0051 
0052     void init();
0053 
0054     void close();
0055 
0056     void defineLevel(LoggerLevel loggerLevel);
0057 
0058     void run();
0059 
0060     void debug(const std::string & className, const std::string & functionName,
0061             const std::string & message);
0062     void info(const std::string & className, const std::string & functionName,
0063             const std::string & message);
0064     void warn(const std::string & className, const std::string & functionName,
0065             const std::string & message);
0066     void error(const std::string & className, const std::string & functionName,
0067             const std::string & message);
0068 
0069     void error(const CustomException &customException);
0070 
0071     void addMessageToBuffer(LoggerMessage loggerMessage);
0072 
0073     std::string toString();
0074 
0075     void flushBuffer();
0076 
0077 private:
0078     static LoggerManager* m_pInstance;
0079 
0080     /**
0081      * Private default constructor for a unique instance
0082      */
0083     LoggerManager();
0084 
0085     sf::Mutex m_mutex;
0086 
0087     std::ofstream m_fileOutputStream;
0088     std::string m_outputFilePath;
0089     LoggerLevel m_defaultLevel;
0090     LoggerPrintMode m_printMode;
0091 
0092     std::map<std::string, LoggerClassLevel*> m_customClassLevels;
0093     std::map<std::string, LoggerClassLevel*>::iterator m_it;
0094 
0095     std::string m_buffer;
0096 
0097     bool m_active;
0098 
0099     void parseConfigurationFile(const std::string &filePath);
0100 
0101     void update();
0102 
0103     bool isLoggable(LoggerMessage loggerMessage);
0104 
0105     void writeConsole();
0106     void writeFile();
0107 };
0108 
0109 } // namespace ElemUtils
0110 
0111 #endif /* LOGGER_MANAGER_H */