Logger.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-20
  6. * Changed: 2023-04-12
  7. *
  8. * */
  9. #ifndef LS_STD_LOGGER_HPP
  10. #define LS_STD_LOGGER_HPP
  11. #include "LogLevel.hpp"
  12. #include <ls-std/core/Class.hpp>
  13. #include <ls-std/core/interface/IWriter.hpp>
  14. #include <ls-std/io/File.hpp>
  15. #include <ls-std/io/FileOutputStream.hpp>
  16. #include <ls-std/os/dynamic-goal.hpp>
  17. #include <string>
  18. namespace ls::std::io
  19. {
  20. class LS_STD_DYNAMIC_GOAL Logger : public ls::std::core::Class
  21. {
  22. public:
  23. explicit Logger(const ::std::shared_ptr<ls::std::core::interface_type::IWriter> &_writer);
  24. ~Logger() noexcept override;
  25. void debug(const ls::std::core::type::byte_type *_data);
  26. void error(const ls::std::core::type::byte_type *_data);
  27. void fatal(const ls::std::core::type::byte_type *_data);
  28. [[nodiscard]] ls::std::io::LogLevel getLogLevel();
  29. void hideLogLevel();
  30. void hideTimestamp();
  31. void info(const ls::std::core::type::byte_type *_data);
  32. void setLogLevel(const ls::std::io::LogLevelValue &_logLevelValue);
  33. void showLogLevel();
  34. void showTimestamp();
  35. void trace(const ls::std::core::type::byte_type *_data);
  36. void warn(const ls::std::core::type::byte_type *_data);
  37. private:
  38. bool displayLogLevel{};
  39. bool displayTimestamp{};
  40. ls::std::io::LogLevel logLevel{};
  41. ::std::shared_ptr<ls::std::core::interface_type::IWriter> writer{};
  42. void _assignWriter(const ::std::shared_ptr<ls::std::core::interface_type::IWriter> &_writer);
  43. [[nodiscard]] static ::std::string _buildCharacterChain(size_t _amount);
  44. [[nodiscard]] static ::std::string _createFillContent(const ::std::string &_text);
  45. [[nodiscard]] static ::std::string _generateTimeString(tm *_localTime);
  46. [[nodiscard]] ::std::string _getLogLevelString(const ls::std::io::LogLevel &_logLevel) const;
  47. [[nodiscard]] ::std::string _getTimestampString() const;
  48. void _log(const ls::std::core::type::byte_type *_data, const ls::std::io::LogLevel &_logLevel);
  49. [[nodiscard]] static ::std::string _padRight(const ::std::string &_text);
  50. };
  51. }
  52. #endif