PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
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(PPath("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  phoenix_assert(log.isOpen());
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(PPath("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(PPath("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(PPath("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(PPath("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(PPath("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(PPath("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 
PString phoenix_logLevelToStr(PLog::Level logLevel)
Convert the log level into a PString.
Definition: PLog.cpp:15
PLog::Level phoenix_strToLogLevel(const PString &str)
Convert a string into a log level.
Definition: PLog.cpp:36
Phoenix Logger.
Definition: PLog.h:21
void setFileName(const PPath &fileName)
Set the output filename of the current PLog.
Definition: PLog.cpp:60
const PPath & getFileName() const
Get the filename of the current log.
Definition: PLog.cpp:252
void setThreadIndex(size_t threadIndex)
Set the thread index of the current PLog.
Definition: PLog.cpp:81
void close()
Close the current PLog and its children.
Definition: PLog.cpp:123
@ CRITICAL
Definition: PLog.h:37
@ INFO
Definition: PLog.h:34
@ DEBUG
Definition: PLog.h:33
@ ERROR
Definition: PLog.h:36
@ ALWAYS
Definition: PLog.h:38
@ WARNING
Definition: PLog.h:35
std::stringstream & getLogString()
Get the log string.
Definition: PLog.cpp:189
void resize(size_t nbThread)
Resize the number of cihldren log file.
Definition: PLog.cpp:88
size_t getThreadIndex() const
Get the thread index of the current PLog.
Definition: PLog.cpp:273
std::ostream & getLogDebug()
Write debug message into the PLog.
Definition: PLog.cpp:209
PLog & getLog(size_t threadIndex)
Get the PLog at given index.
Definition: PLog.cpp:175
std::ostream & getLogInfo()
Write info message into the PLog.
Definition: PLog.cpp:216
void setMode(PLog::Mode mode)
Set the mode of the current PLog.
Definition: PLog.cpp:67
bool isOpen() const
Say if the current PLog is opened or not.
Definition: PLog.cpp:280
std::ostream & getLogWarning()
Write warning message into the PLog.
Definition: PLog.cpp:223
@ STRING_ONLY
Definition: PLog.h:26
@ FILE_CAPTURE_STDOUT_STDERR
Definition: PLog.h:28
@ FILE_ONLY
Definition: PLog.h:25
@ DISABLE
Definition: PLog.h:29
@ STDOUT_ONLY
Definition: PLog.h:27
void setLogLevel(PLog::Level logLevel)
Set the log level of the current PLog.
Definition: PLog.cpp:74
bool open()
Open the current PLog and its children.
Definition: PLog.cpp:104
std::ostream & getLogCritical()
Write critical message into the PLog.
Definition: PLog.cpp:237
void appendLog(std::stringstream &str)
Append the log (STRING_ONLY mode) into an other log.
Definition: PLog.cpp:168
std::ostream & getLogError()
Write error message into the PLog.
Definition: PLog.cpp:230
Path of a directory or a file.
Definition: PPath.h:17
#define phoenix_assert(isOk)
int main(int argc, char **argv)
Definition: main.cpp:290
void testLogStdoutOnly()
Test if the std::cout redirection is working.
Definition: main.cpp:96
void testStringMultiPLog()
Test the PLog.
Definition: main.cpp:67
void testStringToLogLevel()
Test the conversion of string into log level.
Definition: main.cpp:24
void testStringLogAppend()
Test if the STRING_ONLY log mode works.
Definition: main.cpp:120
void testLogDisable()
Test if the std::cout redirection is working.
Definition: main.cpp:109
void testLogLevelToString()
Test the conversion of log level into string.
Definition: main.cpp:14
void testStringPLogLevel()
Test the PLog.
Definition: main.cpp:47
void testStringPLog()
Test the PLog.
Definition: main.cpp:34
void testLogCoutDedirectInFile()
Test if the std::cout redirection is working.
Definition: main.cpp:82