mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-03 21:44:33 +00:00 
			
		
		
		
	Log: generalised Logger class to allow separate logs in Grid-based applications
This commit is contained in:
		@@ -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");
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								lib/Log.h
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								lib/Log.h
									
									
									
									
									
								
							@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user