PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
main.cpp
Go to the documentation of this file.
1 
2 /***************************************
3  Auteur : Pierre Aubert
4  Mail : pierre.aubert@lapp.in2p3.fr
5  Licence : CeCILL-C
6 ****************************************/
7 
8 #include <time.h>
9 #include <iostream>
10 #include "phoenix_assert.h"
11 #include "PLog.h"
12 
21 }
22 
31 }
32 
35  PLog log;
36  log.setFileName("logFile.log");
37  log.setThreadIndex(2lu);
38  phoenix_assert(log.open());
39  phoenix_assert(log.getThreadIndex() == 2lu);
40  phoenix_assert(log.getFileName() == "logFile.log");
41 
42  log.getLog() << "Some log entry" << std::endl;
43  log.getLog() << "Some other log entry" << std::endl;
44 }
45 
48  PLog log;
49  log.setFileName("logLevelFile.log");
51  phoenix_assert(log.open());
52  phoenix_assert(log.getFileName() == "logLevelFile.log");
53  log.getLog(PLog::DEBUG) << "Some debug log entry" << std::endl;
54  log.getLogDebug() << "Some other debug log entry" << std::endl;
55  log.getLog(PLog::INFO) << "Some info log entry" << std::endl;
56  log.getLog() << "Some other info log entry" << std::endl;
57  log.getLogInfo() << "Some other info log entry (again)" << std::endl;
58  log.getLog(PLog::WARNING) << "Some warning log entry" << std::endl;
59  log.getLogWarning() << "Some other warning log entry" << std::endl;
60  log.getLog(PLog::ERROR) << "Some error log entry" << std::endl;
61  log.getLogError() << "Some other error log entry" << std::endl;
62  log.getLog(PLog::CRITICAL) << "Some critical log entry" << std::endl;
63  log.getLogCritical() << "Some other critical log entry" << std::endl;
64 }
65 
68  PLog log;
69  log.setFileName("logMultiFile.log"); //Always set the file name first
70  size_t nbThread(4lu);
71  log.resize(nbThread); //Then, set the number of threads
72  phoenix_assert(log.open()); //Then, open all log file
73  log.getLog() << "Log of all threads" << std::endl;
74  for(size_t i(0lu); i < nbThread; ++i){
75  PLog & subLog = log.getLog(i);
76  subLog.getLog() << " i = "<<i<<", Some log entry" << std::endl;
77  subLog.getLog() << " i = "<<i<<", Some other log entry" << std::endl;
78  }
79 }
80 
83  PLog log;
84  log.setFileName("logFileRedirectCoutCerr.log");
86  phoenix_assert(log.open());
87 
88  std::cout << "Some redirected std::cout stuff" << std::endl;
89  std::cerr << "Some redirected std::cerr stuff" << std::endl;
90  log.getLog() << "Some classic log" << std::endl;
91 
92  log.close(); //Stops the redirection
93 }
94 
97  PLog log;
98  log.setFileName("logFileStdOutOnly.log");
100  phoenix_assert(log.open());
101 
102  log.getLog() << "Some log message" << std::endl;
103  log.getLog() << "Some classic log" << std::endl;
104 
105  log.close(); //Stops the redirection
106 }
107 
110  PLog log;
111  log.setFileName("logFileDisable.log");
112  log.setMode(PLog::DISABLE);
113  phoenix_assert(log.open());
114  log.getLog() << "Some log message" << std::endl;
115  log.getLog() << "Some classic log" << std::endl;
116  log.close(); //Stops the redirection
117 }
118 
121  PLog log;
122  log.setFileName("logFileStringAppend.log");
124  phoenix_assert(log.open());
125  log.getLogInfo() << "Let's test log append" << std::endl;
126 
127  PLog logStr;
128  logStr.setThreadIndex(1lu);
129  logStr.setLogLevel(PLog::DEBUG);
130  logStr.setMode(PLog::STRING_ONLY);
131  phoenix_assert(logStr.open());
132 
133  logStr.getLog(PLog::DEBUG) << "Some debug log entry" << std::endl;
134  logStr.getLogDebug() << "Some other debug log entry" << std::endl;
135  logStr.getLog(PLog::INFO) << "Some info log entry" << std::endl;
136  logStr.getLog() << "Some other info log entry" << std::endl;
137  logStr.getLogInfo() << "Some other info log entry (again)" << std::endl;
138 
139  log.getLogInfo() << "Some log info at the same time (should be before log append)" << std::endl;
140 
141  logStr.getLog(PLog::WARNING) << "Some warning log entry" << std::endl;
142  logStr.getLogWarning() << "Some other warning log entry" << std::endl;
143  logStr.getLog(PLog::ERROR) << "Some error log entry" << std::endl;
144  logStr.getLogError() << "Some other error log entry" << std::endl;
145  logStr.getLog(PLog::CRITICAL) << "Some critical log entry" << std::endl;
146  logStr.getLogCritical() << "Some other critical log entry" << std::endl;
147 
148  log.getLogInfo() << "Just before log append" << std::endl;
149 // logStr.close();
150  log.appendLog(logStr.getLogString());
151  logStr.close();
152  log.getLogInfo() << "Just after log append" << std::endl;
153 
154  log.close();
155 }
156 
157 int main(int argc, char** argv){
160  testStringPLog();
165  testLogDisable();
167  return 0;
168 }
169 
170 
PLog::setThreadIndex
void setThreadIndex(size_t threadIndex)
Set the thread index of the current PLog.
Definition: PLog.cpp:83
PLog.h
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::STDOUT_ONLY
@ STDOUT_ONLY
Definition: PLog.h:25
PLog::CRITICAL
@ CRITICAL
Definition: PLog.h:35
testLogCoutDedirectInFile
void testLogCoutDedirectInFile()
Test if the std::cout redirection is working.
Definition: main.cpp:82
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::close
void close()
Close the current PLog and its children.
Definition: PLog.cpp:125
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
testStringToLogLevel
void testStringToLogLevel()
Test the conversion of string into log level.
Definition: main.cpp:24
PLog::setFileName
void setFileName(const std::string &fileName)
Set the output filename of the current PLog.
Definition: PLog.cpp:62
phoenix_logLevelToStr
std::string phoenix_logLevelToStr(PLog::Level logLevel)
Convert the log level into a string.
Definition: PLog.cpp:17
PLog::FILE_CAPTURE_STDOUT_STDERR
@ FILE_CAPTURE_STDOUT_STDERR
Definition: PLog.h:26
testLogLevelToString
void testLogLevelToString()
Test the conversion of log level into string.
Definition: main.cpp:14
PLog::setLogLevel
void setLogLevel(PLog::Level logLevel)
Set the log level of the current PLog.
Definition: PLog.cpp:76
PLog::getLogDebug
std::ostream & getLogDebug()
Write debug message into the PLog.
Definition: PLog.cpp:211
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
testStringPLogLevel
void testStringPLogLevel()
Test the PLog.
Definition: main.cpp:47
testStringMultiPLog
void testStringMultiPLog()
Test the PLog.
Definition: main.cpp:67
PLog::STRING_ONLY
@ STRING_ONLY
Definition: PLog.h:24
PLog::ALWAYS
@ ALWAYS
Definition: PLog.h:36
PLog::FILE_ONLY
@ FILE_ONLY
Definition: PLog.h:23
PLog::DISABLE
@ DISABLE
Definition: PLog.h:27
testStringLogAppend
void testStringLogAppend()
Test if the STRING_ONLY log mode works.
Definition: main.cpp:120
testLogDisable
void testLogDisable()
Test if the std::cout redirection is working.
Definition: main.cpp:109
phoenix_assert
#define phoenix_assert(isOk)
Definition: phoenix_assert.h:19
PLog::getLogString
std::stringstream & getLogString()
Get the log string.
Definition: PLog.cpp:191
PLog
Phoenix Logger.
Definition: PLog.h:19
testLogStdoutOnly
void testLogStdoutOnly()
Test if the std::cout redirection is working.
Definition: main.cpp:96
PLog::getLogCritical
std::ostream & getLogCritical()
Write critical message into the PLog.
Definition: PLog.cpp:239
phoenix_assert.h
main
int main(int argc, char **argv)
Definition: main.cpp:85
testStringPLog
void testStringPLog()
Test the PLog.
Definition: main.cpp:34
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
phoenix_strToLogLevel
PLog::Level phoenix_strToLogLevel(const std::string &str)
Convert a string into a log level.
Definition: PLog.cpp:38