| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * File: Logger.hpp | ||
| 3 | * Description: Framework logging support | ||
| 4 | * Author: mstarch | ||
| 5 | * | ||
| 6 | * This file adds in support to the core 'Fw' package, to separate it from Os and other loggers, and | ||
| 7 | * allow the architect of the system to select which core framework logging should be used. | ||
| 8 | */ | ||
| 9 | #ifndef Fw_Logger_hpp_ | ||
| 10 | #define Fw_Logger_hpp_ | ||
| 11 | #include <Fw/Deprecate.hpp> | ||
| 12 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 13 | #include <Fw/Types/StringBase.hpp> | ||
| 14 | |||
| 15 | // Unit testing predeclaration hook | ||
| 16 | namespace LoggerRules { | ||
| 17 | struct Register; | ||
| 18 | } | ||
| 19 | |||
| 20 | namespace Fw { | ||
| 21 | class Logger { | ||
| 22 | friend struct LoggerRules::Register; | ||
| 23 | |||
| 24 | public: | ||
| 25 | //! \brief log a formated string with supplied arguments | ||
| 26 | //! | ||
| 27 | //! Logs a format string with the arguments filled-in. This delegates to StringBase.format, which in-turn | ||
| 28 | //! delegates to snprintf. This implies that the caller is fully responsible for handling the type safety of | ||
| 29 | //! the supplied format string. The format string uses C-style (printf function family) formatting. | ||
| 30 | //! \param format: format string | ||
| 31 | //! \param ...: var-args list of arguments to inject into format string. | ||
| 32 | static void log(const char* format, ...); | ||
| 33 | |||
| 34 | //! \brief log a string message directly | ||
| 35 | //! | ||
| 36 | //! Logs the string directly to the backing store without any formatting changes. | ||
| 37 | //! \param message: message to log | ||
| 38 | static void log(const Fw::ConstStringBase& message); | ||
| 39 | |||
| 40 | //! \brief register a logger implementation | ||
| 41 | //! | ||
| 42 | //! This registers the supplied logger as the system logger used for calls to Fw::Logger::log. | ||
| 43 | //! \param logger: logger to register as the system logger | ||
| 44 | static void registerLogger(Logger* logger); | ||
| 45 | |||
| 46 | //! Virtual destructor | ||
| 47 | 10 | virtual ~Logger() = default; | |
| 48 | |||
| 49 | protected: | ||
| 50 | //! \brief write the output of the log message | ||
| 51 | //! | ||
| 52 | //! Log implementations must provide this method used to write the output of a string to the log backing. | ||
| 53 | //! | ||
| 54 | //! \param message: message to log | ||
| 55 | virtual void writeMessage(const ConstStringBase& message) = 0; | ||
| 56 | |||
| 57 | private: | ||
| 58 | static Logger* s_current_logger; //!< Static logger to use when calling Fw::Logger::log function | ||
| 59 | }; | ||
| 60 | } // namespace Fw | ||
| 61 | |||
| 62 | #endif | ||
| 63 |