Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

mql4 log library - MetaTrader 4 library | Trading script download - MT4/MT5 resources

author EAcpu | 4 reads | 0 comments |

This is a logging library that makes it easy to quickly add logging functionality to your code. The library's default behavior matches most situations, but most features can be customized using preprocessor substitutions (#define)

See the sample script on how to use the library.

 #include <logger.mqh> //+--------------------------------------------------------------------------------+
//|Script program startup function |
//+------------------------------------------------------------------+
blank on startup ()
  {
   debug( "this id debug" );
  message( "this is message" );
  Error( "This is an error" );
  } //+------------------------------------------------------------------+


Customization considerations

 // [time, except LOGGER_PRINT,LOGGER_ALERT] [level] [prefix] [message] [last error, only Logger::Error]
Example output: 2021.06.08 17:35:34 | Error | Start | This is a test error | Invalid function parameter value


 #define logger_print1 // print to log
#define logger alert 2 // trigger alert
#define logger_file 4 // write to file
#define logger_notification 8 // send notification

example:

 #define logger_settings_debug0 // debugging is disabled
#Define Logger_Settings_Info1 |2 // Print and Reminder
#Define logger settings error 1 | 2 | 4 // printing, alerting and file writing


 #Define logger prefix __file__ + " | line: " + integer to string ( __line__ ) // [filename] | [line number]
An example of prefix output is: with_customization.mq4 | line: 36
 #define logger_filename "backtest_debug.log"
// or
#Define logger_filename integer to string (account())



Attachment download

📎 logger.mqh (5.49 KB)

📎 no_customization.mq4 (1.11 KB)

📎 with_customization.mq4 (1.6 KB)

Source: MQL5 #35112

Verification code Refresh