1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 01:05:38 +01: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 {
GridStopWatch GridLogger::StopWatch;
std::ostream GridLogger::devnull(0);
GridStopWatch Logger::StopWatch;
std::ostream Logger::devnull(0);
GridLogger GridLogError (1,"Error");
GridLogger GridLogWarning (1,"Warning");

View File

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