거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Simplest Logger class for MetaTrader 5 - MetaTrader 5용 라이브러리

조회수:
2260
평가:
(4)
게시됨:
2024.10.13 21:54
업데이트됨:
2024.10.13 22:10
\MQL5\Include\DKStdLib\Logger\
CDKLogger.mqh (26.27 KB) 조회
\MQL5\Scripts\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Every programmer has their own logger. I wrote my own for MQL5, inspired by the Python logging module.

This class is simplest. No hierarchy, rotators or formatters. It's simple and convenient for any project.

Installation

  1. Copy CDKLogger.mqh to MQL\Include\DKStdLib\Logger folder.
  2. Import CDKLogger class.

#include <DKStdLib\Logger\CDKLogger.mqh

Usage

CDKLogger logger;

// STEP 1. Init Logger with "MyLoggerName" name and INFO level
logger.Init("MyLoggerName", INFO);

// You can change default logger format "%name%:[%level%] %message%" to your own
// Use any pattern combination 
logger.Format = "%YYYY%-%MM%-%DD% %hh%:%mm%-%ss% - %name%:[%level%] %message%"; 

// STEP 2. If you like to filter message only with substings,
//         fill the FilterInList 
// 2.1. Add a substings to FilterIntList
logger.FilterInList.Add("Including-Substring-#1");        
logger.FilterInList.Add("Including-Substring-#2");        

// 2.2. Split string by ";" separator to add all substrings to FilterInList in one line
logger.FilterInFromStringWithSep("Including-Substring-#3;Including-Substring-#4", ";");  

// STEP 3. If you like to filter OUT message with substrings, but leave all others,
//         fill the FilterOutList 
// 3.1. Add a substrings to FilterOutList
logger.FilterOutList.Add("Excluding-Substring-#1");        
logger.FilterOutList.Add("Excluding-Substring-#2");        

// 3.2. Split string by ";" separator to add all substrings to FilterOutList in one line
logger.FilterOutFromStringWithSep("Excluding-Substring-#3;Excluding-Substring-#4", ";");  // use Filter In put your filter str sep by ; here

// STEP 4. Logging
logger.Debug("Debug: Including-Substring-#1", false);                  // Debug with no Alert
logger.Info("Info: Including-Substring-#1", true);                     // Info with Alert dialog
logger.Warn("Warn: Including-Substring-#1"); 
logger.Error("Error: Including-Substring-#1: Excluding-Substring-#1"); // Skipped because of FilterOutList
logger.Critical("Critical: Including-Substring-#1");

logger.Assert(true, 
              "Log msg if true", INFO,   // if ok
              "Log msg if false", ERROR, // if fails
              true);                     // Show Alert as well
logger.Assert(true, 
              "Same msg for true & false", 
              INFO,   // Log level if ok
              ERROR,  // Log level if fails
              false); // No Alert   

The following messages will be output to the log as a result of execution:

Open issues

I often use class this way:

logger.Debug(StringFormat("%s/%d: My message: PARAM1=%f",
                          __FUNCTION__, __LINE__,
                          my_param));

But here we have an issue. StringFormat function parse string every time, even if the logging level does not require the message to be output.

If you need to output debug messages a lot, you'll have to wrap the output in a condition:

if(DEBUG >= logger.Level)                          
  logger.Debug(StringFormat("%s/%d: My message: PARAM1=%f",
                            __FUNCTION__, __LINE__,
                            my_param));      

The best way to do this would be to use StringFormat lazily, but unfortunately MQL5 doesn't support passing a dynamic number of function parameters to the Debug, Info, Error, and so on functions.

If you have any ideas on how this could be done, I'd love to hear them.

TimeServerDaylightSavings TimeServerDaylightSavings

Time-related functions for empirical detection of server time zone and daylight savings mode (DST) from history of quotes

Custom crosshair cursor with synchronization Custom crosshair cursor with synchronization

Synchronized custom crosshair indicator showing price and (server/local) time.

Script to extract Candlesticks data from all time frames to CSV. Script to extract Candlesticks data from all time frames to CSV.

This MQL5 script exports candlestick data for various timeframes into a CSV file, capturing essential market information like open, high, low, and close prices. It analyzes each candlestick's characteristics, including body and wick sizes, while calculating additional metrics such as candle gaps. After processing the latest 21 bars, it notifies the user upon successful data export.

Push Notification for Opened / Closed Trades (Netting) Push Notification for Opened / Closed Trades (Netting)

This code provides a simple function for sending push notifications to your mobile device whenever trades are opened or closed in MetaTrader 5. It's designed for netting accounts (where only one position per symbol is allowed).