mql5/Experts/testRefactor2/Logger.mqh
2026-02-01 21:39:33 +01:00

52 lines
1.5 KiB
MQL5

//+------------------------------------------------------------------+
//| Logger.mqh – centralizované logování, 3 úrovně |
//+------------------------------------------------------------------+
#property copyright "TestRefactor"
#property strict
#ifndef __LOGGER_MQH__
#define __LOGGER_MQH__
enum ENUM_LOG_LEVEL {
LOG_LEVEL_ERROR = 0,
LOG_LEVEL_INFO = 1,
LOG_LEVEL_DEBUG = 2
};
//+------------------------------------------------------------------+
//| CLogger – veškeré logování, rozlišení info / debug / error |
//+------------------------------------------------------------------+
class CLogger {
private:
ENUM_LOG_LEVEL m_minLevel;
string m_prefix;
public:
CLogger(ENUM_LOG_LEVEL minLevel = LOG_LEVEL_INFO, string prefix = "EA")
: m_minLevel(minLevel), m_prefix(prefix) {}
void SetMinLevel(ENUM_LOG_LEVEL level) { m_minLevel = level; }
void SetPrefix(string prefix) { m_prefix = prefix; }
void Error(string msg) {
if(m_minLevel >= LOG_LEVEL_ERROR)
Print("[", m_prefix, " ERROR] ", msg);
}
void Info(string msg) {
if(m_minLevel >= LOG_LEVEL_INFO)
Print("[", m_prefix, " INFO] ", msg);
}
void Debug(string msg) {
if(m_minLevel >= LOG_LEVEL_DEBUG)
Print("[", m_prefix, " DEBUG] ", msg);
}
void InfoFormatted(string msg, double v1, double v2 = 0) {
if(m_minLevel >= LOG_LEVEL_INFO)
Print("[", m_prefix, " INFO] ", msg, " ", DoubleToString(v1, 2), (v2 != 0 ? " " + DoubleToString(v2, 2) : ""));
}
};
#endif