12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-08-20
- * Changed: 2024-09-13
- *
- * */
- #ifndef LS_STD_LOGGER_HPP
- #define LS_STD_LOGGER_HPP
- #include "LogLevel.hpp"
- #include <ls-std/core/Class.hpp>
- #include <ls-std/core/interface/IWriter.hpp>
- #include <ls-std/io/File.hpp>
- #include <ls-std/io/FileOutputStream.hpp>
- #include <ls-std/os/dynamic-goal.hpp>
- #include <string>
- #include <string_view>
- /*
- * @doc: class(name: 'Logger', package: 'io')
- * @doc: io.Logger.description('This is a logger which can log to any implemented target.')
- * */
- namespace ls::std::io
- {
- class LS_STD_DYNAMIC_GOAL Logger : public ls::std::core::Class
- {
- public:
- explicit Logger(const ::std::shared_ptr<ls::std::core::interface_type::IWriter> &_writer);
- ~Logger() noexcept override;
- void debug(const ls::std::core::type::byte_type *_data) const;
- void error(const ls::std::core::type::byte_type *_data) const;
- void fatal(const ls::std::core::type::byte_type *_data) const;
- [[nodiscard]] ls::std::io::LogLevel getLogLevel() const;
- void hideLogLevel();
- void hideTimestamp();
- void info(const ls::std::core::type::byte_type *_data) const;
- void setLogLevel(const ls::std::io::LogLevelValue &_logLevelValue);
- void showLogLevel();
- void showTimestamp();
- void trace(const ls::std::core::type::byte_type *_data) const;
- void warn(const ls::std::core::type::byte_type *_data) const;
- private:
- bool displayLogLevel{};
- bool displayTimestamp{};
- ls::std::io::LogLevel logLevel{};
- ::std::shared_ptr<ls::std::core::interface_type::IWriter> writer{};
- void _assignWriter(const ::std::shared_ptr<ls::std::core::interface_type::IWriter> &_writer);
- [[nodiscard]] static ::std::string _buildCharacterChain(size_t _amount);
- [[nodiscard]] static ::std::string _createFillContent(::std::string_view _text);
- [[nodiscard]] static ::std::string _generateTimeString(const tm *_localTime);
- [[nodiscard]] ::std::string _getLogLevelString(const ls::std::io::LogLevel &_logLevel) const;
- [[nodiscard]] ::std::string _getTimestampString() const;
- void _log(const ls::std::core::type::byte_type *_data, const ls::std::io::LogLevel &_logLevel) const;
- [[nodiscard]] static ::std::string _padRight(const ::std::string &_text);
- };
- }
- #endif
|