Logger.hpp 2.3 KB

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