Logger.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
  3. * Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <string>
  20. #include <fstream>
  21. #include <vector>
  22. /**
  23. * @brief Class used to write lines to the log files as well as the
  24. * standard output.
  25. */
  26. class Logger {
  27. public:
  28. /**
  29. * @brief Initialize the logger.
  30. *
  31. * @param path Path of the log file.
  32. */
  33. Logger(const std::string &path);
  34. ~Logger();
  35. void write(const std::string &message);
  36. void writeDebug(const std::string &message);
  37. void writeWarn(const std::string &message);
  38. void writeError(const std::string &message);
  39. inline bool getDebug() const { return debug; }
  40. inline void setDebug(bool debug) { this->debug = debug; }
  41. private:
  42. std::vector<std::string> log;
  43. std::ofstream logFile;
  44. bool debug;
  45. };