1 #ifndef MOTHUROUT_H 2 #define MOTHUROUT_H 3 4 /* 5 * mothurOut.h 6 * Mothur 7 * 8 * Created by westcott on 2/25/10. 9 * Copyright 2010 Schloss Lab. All rights reserved. 10 * 11 */ 12 13 #include "mothur.h" 14 15 /***********************************************/ 16 struct logger { 17 loggerlogger18 logger() {} ~loggerlogger19 ~logger() {} 20 21 template< class T > 22 logger& operator <<( const T& o ) { 23 //lock_guard<std::mutex> guard(token); 24 cout << o; return *this; 25 } 26 27 logger& operator<<(ostream& (*m)(ostream&) ) { 28 //lock_guard<std::mutex> guard(token); 29 cout << m; return *this; 30 } 31 private: 32 //std::mutex token; 33 }; 34 /***********************************************/ 35 36 class MothurOut { 37 38 public: 39 static MothurOut* getInstance(); 40 41 //logger 42 void appendLogBuffer(string); //used to store log before we establish the logfilename getDebug()43 bool getDebug() { return debug; } setDebug(bool t)44 void setDebug(bool t) { debug = t; } getQuietMode()45 bool getQuietMode() { return quietMode; } setQuietMode(bool t)46 void setQuietMode(bool t) { quietMode = t; } getNumErrors()47 int getNumErrors() { return numErrors; } resetCommandErrors()48 void resetCommandErrors() { control_pressed = false; numCommandErrors = 0; numCommandWarnings = 0; silenceWarnings = false;} getLogFileName()49 string getLogFileName() { return logFileName; } 50 void setLogFileName(string f, bool append); 51 void setHomePath(string); getHomePath()52 string getHomePath() { return homePath; } 53 void setPaths(vector<string>); //environment variable 'PATH' values getPaths()54 vector<string> getPaths() { return paths; } 55 56 void mothurOut(string); //writes to cout and the logfile 57 void mothurOutEndLine(); //writes to cout and the logfile 58 void mothurOutClearBuffer(); 59 void mothurOut(string, ofstream&); //writes to the ofstream, cout and the logfile 60 void mothurOutEndLine(ofstream&); //writes to the ofstream, cout and the logfile 61 void mothurOutJustToScreen(string); //writes to cout 62 void mothurOutJustToLog(string); 63 void errorOut(exception&, string, string); 64 void closeLog(); 65 66 //globals setRandomSeed(unsigned s)67 void setRandomSeed(unsigned s) { seed = s; } getRandomSeed()68 unsigned getRandomSeed() { return seed; } getControl_pressed()69 bool getControl_pressed() { return control_pressed; } setControl_pressed(bool t)70 void setControl_pressed(bool t) { control_pressed = t; } getChangedSeqNames()71 bool getChangedSeqNames() { return changedSeqNames; } setChangedSeqNames(bool t)72 void setChangedSeqNames(bool t) { changedSeqNames = t; } getExecuting()73 bool getExecuting() { return executing; } setExecuting(bool t)74 void setExecuting(bool t) { executing = t; } 75 76 private: 77 static MothurOut* _uniqueInstance; 78 MothurOut( const MothurOut& ); // Disable copy constructor 79 void operator=( const MothurOut& ); // Disable assignment operator MothurOut()80 MothurOut() { 81 control_pressed = false; 82 debug = false; 83 quietMode = false; 84 changedSeqNames = true; 85 silenceLog = false; 86 silenceWarnings = false; //per command 87 numErrors = 0; numWarnings = 0; 88 numCommandErrors = 0; numCommandWarnings = 0; 89 maxCommandErrors = 10; maxCommandWarnings = 10; 90 logFileName = ""; 91 buffer = ""; 92 homePath = ""; 93 outLog = NULL; 94 seed = std::chrono::system_clock::now().time_since_epoch().count(); 95 } 96 ~MothurOut(); 97 98 ofstream* outLog; 99 unsigned seed; 100 int numErrors, numWarnings, numCommandErrors, numCommandWarnings, maxCommandErrors, maxCommandWarnings; 101 string logFileName, buffer, homePath; 102 vector<string> paths; 103 bool changedSeqNames, silenceLog, silenceWarnings, control_pressed, executing, debug, quietMode; 104 }; 105 /***********************************************/ 106 107 108 #endif 109 110