2016-01-02 14:51:32 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: ./lib/Log.h
|
|
|
|
|
|
|
|
Copyright (C) 2015
|
|
|
|
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2016-06-30 16:51:03 +01:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
#ifndef GRID_LOG_H
|
|
|
|
#define GRID_LOG_H
|
|
|
|
namespace Grid {
|
2016-06-30 16:51:03 +01:00
|
|
|
|
|
|
|
// Dress the output; use std::chrono for time stamping via the StopWatch class
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2016-06-30 16:51:03 +01:00
|
|
|
class Colours{
|
|
|
|
protected:
|
|
|
|
bool is_active;
|
|
|
|
public:
|
|
|
|
std::map<std::string, std::string> colour;
|
|
|
|
|
|
|
|
|
|
|
|
Colours(bool activate=false){
|
|
|
|
Active(activate);
|
|
|
|
};
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2016-06-30 16:51:03 +01:00
|
|
|
|
|
|
|
void Active(bool activate){
|
|
|
|
is_active=activate;
|
|
|
|
|
|
|
|
if (is_active){
|
|
|
|
colour["BLACK"] ="\033[30m";
|
|
|
|
colour["RED"] ="\033[31m";
|
|
|
|
colour["GREEN"] ="\033[32m";
|
|
|
|
colour["YELLOW"] ="\033[33m";
|
|
|
|
colour["BLUE"] ="\033[34m";
|
|
|
|
colour["PURPLE"] ="\033[35m";
|
|
|
|
colour["CYAN"] ="\033[36m";
|
|
|
|
colour["WHITE"] ="\033[37m";
|
|
|
|
colour["NORMAL"] ="\033[0;39m";
|
|
|
|
} else {
|
|
|
|
colour["BLACK"] ="";
|
|
|
|
colour["RED"] ="";
|
|
|
|
colour["GREEN"] ="";
|
|
|
|
colour["YELLOW"]="";
|
|
|
|
colour["BLUE"] ="";
|
|
|
|
colour["PURPLE"]="";
|
|
|
|
colour["CYAN"] ="";
|
|
|
|
colour["WHITE"] ="";
|
|
|
|
colour["NORMAL"]="";
|
|
|
|
}
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2016-06-30 16:51:03 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Logger {
|
|
|
|
protected:
|
|
|
|
Colours &Painter;
|
2015-10-27 17:31:13 +00:00
|
|
|
int active;
|
2016-06-30 16:51:03 +01:00
|
|
|
std::string name, topName;
|
|
|
|
std::string COLOUR;
|
|
|
|
|
|
|
|
public:
|
2015-10-27 17:31:13 +00:00
|
|
|
static GridStopWatch StopWatch;
|
|
|
|
static std::ostream devnull;
|
|
|
|
|
2016-06-30 16:51:03 +01:00
|
|
|
std::string background() {return Painter.colour["NORMAL"];}
|
|
|
|
std::string evidence() {return Painter.colour["YELLOW"];}
|
|
|
|
std::string colour() {return Painter.colour[COLOUR];}
|
2015-10-27 17:31:13 +00:00
|
|
|
|
2016-06-30 16:51:03 +01:00
|
|
|
Logger(std::string topNm, int on, std::string nm, Colours& col_class, std::string col)
|
|
|
|
: active(on),
|
|
|
|
name(nm),
|
|
|
|
topName(topNm),
|
|
|
|
Painter(col_class),
|
|
|
|
COLOUR(col){} ;
|
|
|
|
|
|
|
|
void Active(int on) {active = on;};
|
|
|
|
int isActive(void) {return active;};
|
|
|
|
|
|
|
|
friend std::ostream& operator<< (std::ostream& stream, Logger& log){
|
|
|
|
|
|
|
|
if ( log.active ) {
|
2015-10-27 17:31:13 +00:00
|
|
|
StopWatch.Stop();
|
|
|
|
GridTime now = StopWatch.Elapsed();
|
|
|
|
StopWatch.Start();
|
2016-06-30 16:51:03 +01:00
|
|
|
stream << log.background()<< log.topName << log.background()<< " : ";
|
|
|
|
stream << log.colour() <<std::setw(10) << std::left << log.name << log.background() << " : ";
|
|
|
|
stream << log.evidence()<< now << log.background() << " : " << log.colour();
|
2015-10-27 17:31:13 +00:00
|
|
|
return stream;
|
|
|
|
} else {
|
|
|
|
return devnull;
|
|
|
|
}
|
2015-07-23 17:31:13 +01:00
|
|
|
}
|
2015-10-27 17:31:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class GridLogger: public Logger {
|
|
|
|
public:
|
2016-06-30 16:51:03 +01:00
|
|
|
GridLogger(int on, std::string nm, Colours&col_class, std::string col_key = "NORMAL"):
|
|
|
|
Logger("Grid", on, nm, col_class, col_key){};
|
2015-07-23 17:31:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void GridLogConfigure(std::vector<std::string> &logstreams);
|
|
|
|
|
2016-06-30 16:51:03 +01:00
|
|
|
extern GridLogger GridLogError;
|
|
|
|
extern GridLogger GridLogWarning;
|
|
|
|
extern GridLogger GridLogMessage;
|
|
|
|
extern GridLogger GridLogDebug ;
|
|
|
|
extern GridLogger GridLogPerformance;
|
|
|
|
extern GridLogger GridLogIterative ;
|
|
|
|
extern GridLogger GridLogIntegrator ;
|
|
|
|
extern Colours GridLogColours;
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2016-06-30 16:51:03 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
}
|
|
|
|
#endif
|