💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.1 KiB

  1. /*
  2. * Copyright (C) 2020 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_LOGGER_HPP
  20. #define ANTKEEPER_LOGGER_HPP
  21. #include <list>
  22. #include <ostream>
  23. #include <string>
  24. class logger
  25. {
  26. public:
  27. logger();
  28. ~logger();
  29. /**
  30. * Redirects log output to the specified output stream.
  31. *
  32. * @param stream Output stream to which log text will be written.
  33. */
  34. void redirect(std::ostream* stream);
  35. /**
  36. * Outputs text to the log.
  37. */
  38. void log(const std::string& text);
  39. void warning(const std::string& text);
  40. void error(const std::string& text);
  41. void success(const std::string& text);
  42. void set_log_prefix(const std::string& prefix);
  43. void set_log_postfix(const std::string& postfix);
  44. void set_warning_prefix(const std::string& prefix);
  45. void set_warning_postfix(const std::string& postfix);
  46. void set_error_prefix(const std::string& prefix);
  47. void set_error_postfix(const std::string& postfix);
  48. void set_success_prefix(const std::string& prefix);
  49. void set_success_postfix(const std::string& postfix);
  50. void push_prefix(const std::string& prefix);
  51. void pop_prefix();
  52. private:
  53. std::ostream* os;
  54. std::string log_prefix;
  55. std::string log_postfix;
  56. std::string warning_prefix;
  57. std::string warning_postfix;
  58. std::string error_prefix;
  59. std::string error_postfix;
  60. std::string success_prefix;
  61. std::string success_postfix;
  62. std::list<std::string> prefix_stack;
  63. };
  64. #endif // ANTKEEPER_LOGGER_HPP