Logger.hpp 2.3 KB

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