log.h 655 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef _LOG_H_
  2. #define _LOG_H_
  3. #include "const.h"
  4. #include <fstream>
  5. using namespace std;
  6. static class LogUnit {
  7. ofstream logFile;
  8. public:
  9. bool openLog(const char * filename);
  10. void closeLog();
  11. ~LogUnit() { closeLog(); }
  12. template<typename Type>
  13. LogUnit & operator<<(const Type & text) {
  14. logFile << text; logFile.flush();
  15. return *this;
  16. }
  17. LogUnit & operator<<(ostream & (*fp)(ostream&)) {
  18. logFile << fp; logFile.flush();
  19. return *this;
  20. }
  21. LogUnit & operator<<(ios_base & (*fp)(ios_base&)) {
  22. logFile << fp; logFile.flush();
  23. return *this;
  24. }
  25. } logStream;
  26. #endif