1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Log: generalised Logger class to allow separate logs in Grid-based applications

This commit is contained in:
Antonin Portelli 2015-10-27 17:31:13 +00:00 committed by Antonin Portelli
parent 1b22ce5720
commit 8709117aea
2 changed files with 33 additions and 25 deletions

View File

@ -2,8 +2,8 @@
namespace Grid { namespace Grid {
GridStopWatch GridLogger::StopWatch; GridStopWatch Logger::StopWatch;
std::ostream GridLogger::devnull(0); std::ostream Logger::devnull(0);
GridLogger GridLogError (1,"Error"); GridLogger GridLogError (1,"Error");
GridLogger GridLogWarning (1,"Warning"); GridLogger GridLogWarning (1,"Warning");

View File

@ -6,31 +6,39 @@ namespace Grid {
std::ostream& operator<< (std::ostream& stream, const GridTime& time); std::ostream& operator<< (std::ostream& stream, const GridTime& time);
class GridLogger { class Logger {
int active; protected:
std::string name; int active;
std::string name, topName;
public: public:
static GridStopWatch StopWatch;
static GridStopWatch StopWatch; static std::ostream devnull;
static std::ostream devnull;
Logger(std::string topNm, int on, std::string nm)
GridLogger(int on, std::string nm): active(on), name(nm) { : active(on), name(nm), topName(topNm) {};
};
void Active(int on) {active = on;};
void Active(int on) {active = on;}; int isActive(void) {return active;};
friend std::ostream& operator<< (std::ostream& stream, const GridLogger& log){ friend std::ostream& operator<< (std::ostream& stream, const Logger& log){
if ( log.active ) { if ( log.active ) {
StopWatch.Stop(); StopWatch.Stop();
GridTime now = StopWatch.Elapsed(); GridTime now = StopWatch.Elapsed();
StopWatch.Start(); StopWatch.Start();
stream << "Grid : "<<log.name << " : " << now << " : "; stream << std::setw(8) << std::left << log.topName << " : ";
return stream; stream << std::setw(12) << std::left << log.name << " : ";
} else { stream << now << " : ";
return devnull; return stream;
} else {
return devnull;
}
} }
}
};
class GridLogger: public Logger {
public:
GridLogger(int on, std::string nm): Logger("Grid", on, nm){};
}; };
void GridLogConfigure(std::vector<std::string> &logstreams); void GridLogConfigure(std::vector<std::string> &logstreams);