PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
PLog.h
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #ifndef __PLOG_H__
8 #define __PLOG_H__
9 
10 #include <string>
11 #include <iostream>
12 #include <fstream>
13 #include <sstream>
14 #include <vector>
15 
16 class PLog;
17 
19 class PLog{
20  public:
22  enum Mode{
28  };
30  enum Level{
31  DEBUG = 1,
32  INFO = 2,
33  WARNING = 3,
34  ERROR = 4,
35  CRITICAL = 5,
36  ALWAYS = 6
37  };
38  PLog();
39  virtual ~PLog();
40 
41  void setFileName(const std::string & fileName);
42  void setMode(PLog::Mode mode);
43  void setLogLevel(PLog::Level logLevel);
44  void setThreadIndex(size_t threadIndex);
45  void resize(size_t nbThread);
46  bool open();
47  void close();
48  void clear();
49  void appendLog(std::stringstream & str);
50 
51  PLog & getLog(size_t threadIndex);
52  std::ofstream & getLogFile();
53  std::stringstream & getLogString();
54  std::ostream & getLog(PLog::Level logLevel = PLog::INFO);
55  std::ostream & getLogDebug();
56  std::ostream & getLogInfo();
57  std::ostream & getLogWarning();
58  std::ostream & getLogError();
59  std::ostream & getLogCritical();
60  std::ostream & getLogAlways();
61 
62  const std::string & getFileName() const;
63  PLog::Mode getMode() const;
64  PLog::Level getLogLevel() const;
65  size_t getThreadIndex() const;
66 
67  private:
68  void initialisationPLog();
69  void allocateStream(std::streambuf* buffer);
70  bool streamOpen();
71 
77  std::string p_fileName;
79  std::ofstream p_logFile;
81  std::stringstream p_logString;
83  std::ostream * p_stream;
85  std::ostream * p_nullStream;
87  std::streambuf* p_oldStdCerrBuffer;
89  std::streambuf* p_oldStdCoutBuffer;
91  std::vector<PLog*> p_vecLog;
93  bool p_isOpen;
95  size_t p_threadIndex;
96 };
97 
98 std::string phoenix_logLevelToStr(PLog::Level logLevel);
99 PLog::Level phoenix_strToLogLevel(const std::string & str);
100 
101 #endif
102 
PLog::setThreadIndex
void setThreadIndex(size_t threadIndex)
Set the thread index of the current PLog.
Definition: PLog.cpp:83
PLog::getLog
PLog & getLog(size_t threadIndex)
Get the PLog at given index.
Definition: PLog.cpp:177
PLog::getFileName
const std::string & getFileName() const
Get the filename of the current log.
Definition: PLog.cpp:254
PLog::WARNING
@ WARNING
Definition: PLog.h:33
PLog::initialisationPLog
void initialisationPLog()
Initialisation function of the class PLog.
Definition: PLog.cpp:280
PLog::Mode
Mode
Mode to be used on the logger.
Definition: PLog.h:22
PLog::STDOUT_ONLY
@ STDOUT_ONLY
Definition: PLog.h:25
PLog::CRITICAL
@ CRITICAL
Definition: PLog.h:35
PLog::ERROR
@ ERROR
Definition: PLog.h:34
PLog::DEBUG
@ DEBUG
Definition: PLog.h:31
PLog::getLogError
std::ostream & getLogError()
Write error message into the PLog.
Definition: PLog.cpp:232
PLog::allocateStream
void allocateStream(std::streambuf *buffer)
Allocate the stream.
Definition: PLog.cpp:294
PLog::close
void close()
Close the current PLog and its children.
Definition: PLog.cpp:125
PLog::getLogAlways
std::ostream & getLogAlways()
Write always message into the PLog.
Definition: PLog.cpp:246
PLog::appendLog
void appendLog(std::stringstream &str)
Append the log (STRING_ONLY mode) into an other log.
Definition: PLog.cpp:170
PLog::getLogWarning
std::ostream & getLogWarning()
Write warning message into the PLog.
Definition: PLog.cpp:225
PLog::setFileName
void setFileName(const std::string &fileName)
Set the output filename of the current PLog.
Definition: PLog.cpp:62
PLog::FILE_CAPTURE_STDOUT_STDERR
@ FILE_CAPTURE_STDOUT_STDERR
Definition: PLog.h:26
PLog::p_logFile
std::ofstream p_logFile
Current log file to be used.
Definition: PLog.h:79
PLog::p_isOpen
bool p_isOpen
True of the log is opened.
Definition: PLog.h:93
PLog::clear
void clear()
Clear the children of the current PLog.
Definition: PLog.cpp:155
PLog::getLogLevel
PLog::Level getLogLevel() const
Get the log level of the current PLog.
Definition: PLog.cpp:268
phoenix_logLevelToStr
std::string phoenix_logLevelToStr(PLog::Level logLevel)
Convert the log level into a string.
Definition: PLog.cpp:17
PLog::setLogLevel
void setLogLevel(PLog::Level logLevel)
Set the log level of the current PLog.
Definition: PLog.cpp:76
PLog::p_oldStdCoutBuffer
std::streambuf * p_oldStdCoutBuffer
Old std::cout buffer.
Definition: PLog.h:89
PLog::getLogDebug
std::ostream & getLogDebug()
Write debug message into the PLog.
Definition: PLog.cpp:211
PLog::p_stream
std::ostream * p_stream
Current stream to be used to log things.
Definition: PLog.h:83
PLog::~PLog
virtual ~PLog()
Destructor of PLog.
Definition: PLog.cpp:53
PLog::getLogInfo
std::ostream & getLogInfo()
Write info message into the PLog.
Definition: PLog.cpp:218
PLog::resize
void resize(size_t nbThread)
Resize the number of cihldren log file.
Definition: PLog.cpp:90
PLog::setMode
void setMode(PLog::Mode mode)
Set the mode of the current PLog.
Definition: PLog.cpp:69
PLog::open
bool open()
Open the current PLog and its children.
Definition: PLog.cpp:106
PLog::streamOpen
bool streamOpen()
Open the streams.
Definition: PLog.cpp:304
PLog::p_fileName
std::string p_fileName
Output filename of the current PLog.
Definition: PLog.h:77
PLog::STRING_ONLY
@ STRING_ONLY
Definition: PLog.h:24
PLog::getMode
PLog::Mode getMode() const
Get the mode of the current PLog.
Definition: PLog.cpp:261
PLog::ALWAYS
@ ALWAYS
Definition: PLog.h:36
PLog::p_nullStream
std::ostream * p_nullStream
Stream used to disable log output.
Definition: PLog.h:85
PLog::p_vecLog
std::vector< PLog * > p_vecLog
Vector of sur log file to be used (mainly for multithreaded programs)
Definition: PLog.h:91
PLog::getLogFile
std::ofstream & getLogFile()
Get the current log file.
Definition: PLog.cpp:184
PLog::FILE_ONLY
@ FILE_ONLY
Definition: PLog.h:23
createReleaseCurl.str
str
Definition: createReleaseCurl.py:128
PLog::DISABLE
@ DISABLE
Definition: PLog.h:27
PLog::p_oldStdCerrBuffer
std::streambuf * p_oldStdCerrBuffer
Old std::cerr buffer.
Definition: PLog.h:87
PLog::getLogString
std::stringstream & getLogString()
Get the log string.
Definition: PLog.cpp:191
PLog
Phoenix Logger.
Definition: PLog.h:19
PLog::p_logLevel
PLog::Level p_logLevel
Current log level of the PLog (all log greater or equal to the p_logLevel will be logged)
Definition: PLog.h:75
PLog::p_threadIndex
size_t p_threadIndex
Index of the current thread.
Definition: PLog.h:95
PLog::p_logString
std::stringstream p_logString
Log string.
Definition: PLog.h:81
PLog::getLogCritical
std::ostream & getLogCritical()
Write critical message into the PLog.
Definition: PLog.cpp:239
PLog::Level
Level
Log level to be used in the logger.
Definition: PLog.h:30
PLog::p_mode
PLog::Mode p_mode
Mode of the logger.
Definition: PLog.h:73
phoenix_strToLogLevel
PLog::Level phoenix_strToLogLevel(const std::string &str)
Convert a string into a log level.
Definition: PLog.cpp:38
PLog::getThreadIndex
size_t getThreadIndex() const
Get the thread index of the current PLog.
Definition: PLog.cpp:275
PLog::INFO
@ INFO
Definition: PLog.h:32
PLog::PLog
PLog()
Default constructor of PLog.
Definition: PLog.cpp:48