Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS // For Windows-Users (ctime gets warnings) - all other can delete or ignore this line
  2. #include <ctime>
  3.  
  4. #include "logger.hpp"
  5. #include "policy.hpp"
  6. #include "consolepolicy.hpp"
  7.  
  8. using namespace std;
  9.  
  10. /// \brief Helper function to get a time-string with second resolution.
  11. static std::string getTimeString()
  12. {
  13. std::string timeStr;
  14. time_t rawTime;
  15. time( &rawTime );
  16. timeStr = ctime( &rawTime );
  17. return timeStr.substr( 0 , timeStr.size() - 1 );
  18. }
  19.  
  20. void Logger::write(const std::string & file, long line, const std::string & message)
  21. {
  22. if (_cpolicies == NULL) {
  23. m_history = m_history + file + " " + to_string(line) + " " + message + " " + getTimeString();
  24. m_history += "\n";
  25. }
  26. else
  27. {
  28. std::string logtxt = file + " " + to_string(line) + " " + message + " " + getTimeString() + "\n";;
  29. _cpolicies->write(logtxt);
  30. }
  31. }
  32.  
  33. void Logger::registerPolicy(std::unique_ptr<Policy> _policy)
  34. {
  35. if (_cpolicies == NULL) {
  36. _cpolicies = std::move(_policy);
  37. _cpolicies->write(m_history);
  38. }
  39. else
  40. {
  41. _cpolicies = std::move(_policy);
  42. }
  43. }
  44.  
  45. Logger & Logger::instance()
  46. {
  47. static Logger theOneAndOnly;
  48. return theOneAndOnly;
  49. // TODO: hier Rückgabeanweisung eingeben
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement