Logger.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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-13
  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. * @doc: io.Logger.description('This is a logger which can log to any implemented target.')
  22. * */
  23. namespace ls::std::io
  24. {
  25. class LS_STD_DYNAMIC_GOAL Logger : public ls::std::core::Class
  26. {
  27. public:
  28. explicit Logger(const ::std::shared_ptr<ls::std::core::interface_type::IWriter> &_writer);
  29. ~Logger() noexcept override;
  30. void debug(const ls::std::core::type::byte_type *_data) const;
  31. void error(const ls::std::core::type::byte_type *_data) const;
  32. void fatal(const ls::std::core::type::byte_type *_data) const;
  33. [[nodiscard]] ls::std::io::LogLevel getLogLevel() const;
  34. void hideLogLevel();
  35. void hideTimestamp();
  36. void info(const ls::std::core::type::byte_type *_data) const;
  37. void setLogLevel(const ls::std::io::LogLevelValue &_logLevelValue);
  38. void showLogLevel();
  39. void showTimestamp();
  40. void trace(const ls::std::core::type::byte_type *_data) const;
  41. void warn(const ls::std::core::type::byte_type *_data) const;
  42. private:
  43. bool displayLogLevel{};
  44. bool displayTimestamp{};
  45. ls::std::io::LogLevel logLevel{};
  46. ::std::shared_ptr<ls::std::core::interface_type::IWriter> writer{};
  47. void _assignWriter(const ::std::shared_ptr<ls::std::core::interface_type::IWriter> &_writer);
  48. [[nodiscard]] static ::std::string _buildCharacterChain(size_t _amount);
  49. [[nodiscard]] static ::std::string _createFillContent(::std::string_view _text);
  50. [[nodiscard]] static ::std::string _generateTimeString(const tm *_localTime);
  51. [[nodiscard]] ::std::string _getLogLevelString(const ls::std::io::LogLevel &_logLevel) const;
  52. [[nodiscard]] ::std::string _getTimestampString() const;
  53. void _log(const ls::std::core::type::byte_type *_data, const ls::std::io::LogLevel &_logLevel) const;
  54. [[nodiscard]] static ::std::string _padRight(const ::std::string &_text);
  55. };
  56. }
  57. #endif