#include <simple_logger.hpp>
|
void | dump (string type, string msg, bool autoFormat=true) |
| Dumps a message to console. More...
|
|
string | dumpStats (int which) |
| Dump statistics onto console. More...
|
|
bool | isDir (const std::string &name) |
| Checks if given directory path exists on system. More...
|
|
std::string | log (string type, const string &msg) |
| Compose a message and log to logging file. More...
|
|
template<typename A , typename B > |
string | mapToString (const map< A, B > &m, string title="") const |
|
template<typename A , typename B > |
void | mapToXML (ostringstream &ss, const map< A, B > &m, const char *tagName, unsigned indent) const |
| Converts a map to XML like staructure. More...
|
|
string | save (const char *outFile="") |
| Convert this logger to XML. More...
|
|
| SimpleLogger () |
| Constructor of logger. The wrapper script of moose must make sure that $HOME/.moose is created. The logger will write to $HOME/.moose/log. More...
|
|
const std::string | timeStamp () |
| Get current timestamp. More...
|
|
void | updateGlobalCount (string type) |
| When an element is created in moose, log its presense in this map. More...
|
|
| ~SimpleLogger () |
|
Definition at line 69 of file simple_logger.hpp.
SimpleLogger::SimpleLogger |
( |
| ) |
|
|
inline |
Constructor of logger. The wrapper script of moose must make sure that $HOME/.moose is created. The logger will write to $HOME/.moose/log.
Definition at line 78 of file simple_logger.hpp.
83 logSS <<
"<log simulator=\"moose\">" << endl;
85 logSS <<
"\t<messages>" << endl;
const std::string timeStamp()
Get current timestamp.
SimpleLogger::~SimpleLogger |
( |
| ) |
|
|
inline |
void SimpleLogger::dump |
( |
string |
type, |
|
|
string |
msg, |
|
|
bool |
autoFormat = true |
|
) |
| |
|
inline |
Dumps a message to console.
- Parameters
-
type | Type of message e.g. WARN, ERROR, FATAL etc. |
msg | Message to dump. |
autoFormat | Use ` to demarcate coloring of output. |
Definition at line 279 of file simple_logger.hpp.
References T_BLUE, T_CYAN, T_GREEN, T_MAGENTA, T_RED, T_RESET, and T_YELLOW.
288 ss <<
"[" << type <<
"] ";
292 if(type ==
"WARNING" || type ==
"WARN" || type ==
"FIXME")
294 else if(type ==
"DEBUG")
296 else if(type ==
"ERROR" || type ==
"FAIL" || type ==
"FATAL" || type ==
"ASSERT_FAILURE")
298 else if(type ==
"INFO" || type ==
"EXPECT_FAILURE")
300 else if(type ==
"LOG")
303 for(
unsigned int i = 0; i < msg.size(); ++i)
313 else if(set && !reset)
320 else if(
'\n' == msg[i])
330 logSS << ss.str() << endl;
331 cerr << ss.str() << endl;
string SimpleLogger::dumpStats |
( |
int |
which | ) |
|
|
inline |
Dump statistics onto console.
- Parameters
-
which | If which is 0 then print elements inside moose, if it is 1 then print total time taken during simulation. |
- Returns
Definition at line 159 of file simple_logger.hpp.
165 ss << mapToString<string, unsigned long>(
elementsMap,
"data_structure");
179 timekeeperMap[
"Creation"] = accumulate(
185 ss << mapToString<string, float>(
timekeeperMap,
"simulation_stats" );
map< string, unsigned long > elementsMap
vector< float > simulationTime
map< string, float > timekeeperMap
vector< float > initializationTime
vector< float > creationTime
bool SimpleLogger::isDir |
( |
const std::string & |
name | ) |
|
|
inline |
Checks if given directory path exists on system.
- Parameters
-
name | Directory path as string. |
- Returns
- true, if directory exists, false otherwise.
Definition at line 257 of file simple_logger.hpp.
261 int result = _stat(
name.c_str(), &buf );
264 int result = stat(
name.c_str(), &buf );
266 if(result == 0 && S_ISDIR(buf.st_mode))
std::string SimpleLogger::log |
( |
string |
type, |
|
|
const string & |
msg |
|
) |
| |
|
inline |
Compose a message and log to logging file.
- Parameters
-
- Returns
Definition at line 344 of file simple_logger.hpp.
350 logF.open(
outputFile.c_str(), std::fstream::out | std::fstream::app);
351 ss <<
"<" << type <<
" time=\"" << time <<
"\">";
352 ss << msg <<
"</" << type <<
">" << endl;
355 string newmsg = ss.str();
const std::string timeStamp()
Get current timestamp.
template<typename A , typename B >
string SimpleLogger::mapToString |
( |
const map< A, B > & |
m, |
|
|
string |
title = "" |
|
) |
| const |
|
inline |
Definition at line 130 of file simple_logger.hpp.
136 for(
unsigned i = 0; i < width - title.size(); ++i)
140 typename map<A, B>::const_iterator it;
141 for( it = m.begin(); it != m.end(); it++)
142 ss << setw(width/2) << it->first << setw(width/2) << it->second << endl;
144 for(
unsigned i = 0; i < width; ++i)
template<typename A , typename B >
void SimpleLogger::mapToXML |
( |
ostringstream & |
ss, |
|
|
const map< A, B > & |
m, |
|
|
const char * |
tagName, |
|
|
unsigned |
indent |
|
) |
| const |
|
inline |
Converts a map to XML like staructure.
- Template Parameters
-
- Parameters
-
ss | Input ostringstream. |
m | std::map |
tagName | This is current tag name. Useful when recursing. |
indent | Usually a tag character. |
Definition at line 202 of file simple_logger.hpp.
206 for(
unsigned int i = 0; i < indent; ++i)
208 ss << prefix <<
"<" << tagName <<
">" << endl;
210 typename map<A, B>::const_iterator it;
211 for(it = m.begin(); it != m.end(); it++)
213 ss << prefix << prefix
214 <<
"<" << it->first <<
">"
216 <<
"</" << it->first <<
">" << endl;
219 ss << prefix <<
"</" << tagName <<
">" << endl;
string SimpleLogger::save |
( |
const char * |
outFile = "" | ) |
|
|
inline |
Convert this logger to XML.
- Returns
- A XML string.
Definition at line 227 of file simple_logger.hpp.
229 string logFile = string(outFile);
230 if(logFile.size() == 0)
234 logSS <<
"\t</messages>" << endl;
239 logSS <<
"\t<end_time>" <<
timeStamp() <<
"</end_time>" << endl;
241 logSS <<
"</log>" << endl;
244 logF.open(logFile.c_str(), std::fstream::out | std::fstream::app);
map< string, unsigned long > elementsMap
map< string, float > timekeeperMap
const std::string timeStamp()
Get current timestamp.
const std::string SimpleLogger::timeStamp |
( |
| ) |
|
|
inline |
Get current timestamp.
- Returns
- A string represeting current timestamp.
Definition at line 104 of file simple_logger.hpp.
106 time_t now = time(0);
109 tstruct = *localtime(&now);
110 strftime(buf,
sizeof(buf),
"%Y-%m-%d.%X", &tstruct);
void SimpleLogger::updateGlobalCount |
( |
string |
type | ) |
|
|
inline |
When an element is created in moose, log its presense in this map.
- Parameters
-
type | Type of element. |
path | Path of the element. |
Definition at line 121 of file simple_logger.hpp.
map< string, unsigned long > elementsMap
vector<float> SimpleLogger::creationTime |
map<string, unsigned long> SimpleLogger::elementsMap |
|
private |
string SimpleLogger::endTime |
string SimpleLogger::homeDir |
vector<float> SimpleLogger::initializationTime |
ostringstream SimpleLogger::logSS |
string SimpleLogger::mooseDir |
string SimpleLogger::outputFile |
vector<float> SimpleLogger::simulationTime |
string SimpleLogger::startTime |
map<string, float> SimpleLogger::timekeeperMap |
|
private |
The documentation for this class was generated from the following file: