2026-08-27 18:09:07 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| SimpleLogger.mqh |
|
| | | //| Copyright 2025, Niquel Mendoza. |
|
| | | //| https://www.mql5.com/es/users/nique_372/news |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2025, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com/es/users/nique_372/news"
|
| | | #property strict
|
| | |
|
| | |
|
| | | #ifndef MQLARTICLES_UTILS_FA_SIMPLELOGGER_MQH
|
| | | #define MQLARTICLES_UTILS_FA_SIMPLELOGGER_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "LoggerDef.mqh"
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Base Logging Class with Flag System |
|
| | | //+------------------------------------------------------------------+
|
| | | class CLoggerBase
|
| | | {
|
| | | private:
|
| | | uint8_t m_log_flags; // Active logging flags
|
| | | uint8_t m_last_flags; // Last active logging flags
|
| | |
|
| | |
|
| | | //--- Main logging method with flags
|
| | | __forceinline void RemoveFlag(uint8_t flags) { this.m_log_flags &= ~flags; }
|
| | |
|
| | | protected:
|
| | | //--- Flag-specific methods
|
| | | __forceinline void LogWarning(const string &message, const string &function) const;
|
| | | __forceinline void LogInfo(const string &message, const string &function) const;
|
| | | __forceinline void LogCaution(const string &message, const string &function) const;
|
| | |
|
| | | public:
|
| | | CLoggerBase();
|
| | | ~CLoggerBase() {}
|
| | |
|
| | | //---
|
| | | void ForceRemoveLogErrors();
|
| | | static __forceinline void LogError(const string &message, const string &function);
|
| | | static __forceinline void LogFatalError(const string &message, const string &function);
|
| | | static __forceinline void LogCriticalError(const string &message, const string &function);
|
| | |
|
| | |
|
| | | //--- Methods to check if a flag is active
|
| | | __forceinline bool IsWarningLogEnabled() const { return (m_log_flags & LOG_LEVEL_WARNING) != 0; }
|
| | | __forceinline bool IsInfoLogEnabled() const { return (m_log_flags & LOG_LEVEL_INFO) != 0; }
|
| | | __forceinline bool IsCautionLogEnabled() const { return (m_log_flags & LOG_LEVEL_CAUTION) != 0; }
|
| | |
|
| | | //--- Getters
|
| | | __forceinline uint8_t LogFlags() const { return m_log_flags; }
|
| | | inline bool IsLogEnabled(uint8_t flag) const { return (m_log_flags & flag) != 0; }
|
| | |
|
| | | //--- Main configuration using flags
|
| | | virtual inline void AddLogFlags(const uint8_t flags);
|
| | | virtual void RemoveLogFlags(const uint8_t flags);
|
| | | inline void ResetLastStateFlags() { this.m_log_flags = m_last_flags; }
|
| | |
|
| | | //--- Disbale and Enable all logs
|
| | | virtual void EnableAllLogs();
|
| | | virtual void DisableAllLogs();
|
| | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Constructor |
|
| | | //+------------------------------------------------------------------+
|
| | | CLoggerBase::CLoggerBase(void)
|
| | | {
|
| | | this.m_log_flags = LOG_LEVEL_ERROR;
|
| | | this.m_last_flags = LOG_LEVEL_ERROR;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | void CLoggerBase::ForceRemoveLogErrors(void)
|
| | | {
|
| | | this.m_last_flags = m_log_flags;
|
| | | RemoveFlag(LOG_LEVEL_ERROR);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | void CLoggerBase::DisableAllLogs()
|
| | | {
|
| | | m_log_flags = LOG_LEVEL_ERROR;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | void CLoggerBase::EnableAllLogs(void)
|
| | | {
|
| | | m_log_flags |= LOG_ALL;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | inline void CLoggerBase::AddLogFlags(const uint8_t flags)
|
| | | {
|
| | | this.m_last_flags = m_log_flags;
|
| | | m_log_flags |= flags;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | void CLoggerBase::RemoveLogFlags(const uint8_t flags)
|
| | | {
|
| | | this.m_last_flags = m_log_flags;
|
| | | uint8_t safe_flags = flags & ~LOG_LEVEL_ERROR;
|
| | | RemoveFlag(safe_flags);
|
| | | m_log_flags |= LOG_LEVEL_ERROR;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Métodos específicos por flag |
|
| | | //+------------------------------------------------------------------+
|
| | | static __forceinline void CLoggerBase::LogError(const string &message, const string& function)
|
| | | {
|
| | | FastLog(function, ERROR_TEXT, message);
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | static __forceinline void CLoggerBase::LogCriticalError(const string &message, const string& function)
|
| | | {
|
| | | FastLog(function, CRITICAL_ERROR_TEXT, message);
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | static __forceinline void CLoggerBase::LogFatalError(const string &message, const string& function)
|
| | | {
|
| | | FastLog(function, FATAL_ERROR_TEXT, message);
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | __forceinline void CLoggerBase::LogWarning(const string &message, const string& function) const
|
| | | {
|
| | | if((m_log_flags & LOG_LEVEL_WARNING) != 0)
|
| | | FastLog(function, WARNING_TEXT, message);
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | __forceinline void CLoggerBase::LogInfo(const string &message, const string& function) const
|
| | | {
|
| | | if((m_log_flags & LOG_LEVEL_INFO) != 0)
|
| | | FastLog(function, INFO_TEXT, message);
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | __forceinline void CLoggerBase::LogCaution(const string &message, const string& function) const
|
| | | {
|
| | | if((m_log_flags & LOG_LEVEL_CAUTION) != 0)
|
| | | FastLog(function, CAUTION_TEXT, message);
|
| | | }
|
| | |
|
| | | #endif
|
| | | //+------------------------------------------------------------------+
|