MT5 Logging API
- librerie
- COSTEL VLAD
- Versione: 1.0
This simple logging library is designed to provide clear and contextual log output with minimal hassle. It exposes five methods:
- LogErrorMessage(message)
- LogWarnMessage(message)
- LogInfoMessage(message)
- LogDebugMessage(message)
- LogTraceMessage(message)
Each method prints the provided message to the console only if the severity level meets or exceeds the current threshold set by a global variable logLevel. This means you control the verbosity of your application's logs by adjusting logLevel.
What sets this library apart is its built-in context awareness: every log message is automatically prefixed with the source file name, the exact line number, and the function from which the call originated. This provides pinpoint accuracy when tracking down issues and simplifies the debugging process.
By combining tidy output control with detailed contextual information, this library is an ideal tool for developers who need to quickly identify and resolve issues while keeping their code clean and maintainable.
You can download the free source code of this library from github and you can include it directly in your EA code; please note that the source file is compatible with both MT4 and MT5 platforms.
Here is an example of use:
#define LOGLEVEL_OFF 0 #define LOGLEVEL_ERROR 1 #define LOGLEVEL_WARNING 2 #define LOGLEVEL_INFO 3 #define LOGLEVEL_DEBUG 4 #define LOGLEVEL_TRACE 5 // Include the logging API header #import "vladefix/logging-api-v1.00.ex5" void SetLoggerLevel(int); void LogErrorMessage(string); void LogWarnMessage(string); void LogInfoMessage(string); void LogDebugMessage(string); void LogTraceMessage(string); #import //------------------------------------------------------- // Initialization function (OnInit) //------------------------------------------------------- int OnInit() { /* Set the global log level using one of the predefined log levels: LOGLEVEL_OFF -> No logging at all LOGLEVEL_ERROR -> Only error messages LOGLEVEL_WARNING -> Errors and warnings LOGLEVEL_INFO -> Information messages and above LOGLEVEL_DEBUG -> Debug messages (and above) LOGLEVEL_TRACE -> All logging messages */ SetLoggerLevel(LOGLEVEL_INFO); // For this example, we log info and above. return INIT_SUCCEEDED; } //------------------------------------------------------- // Main tick event handler //------------------------------------------------------- void OnTick() { // Log an informational message on each tick. LogInfoMessage("OnTick event triggered."); }
