I read your "Best Logging Class" name, which attracted my attention. "Best" is placing the level quite high, so I was curious to check that. I will avoid to talk about the details, as it's a freely distributed code which requires to be indulgent.
Usage and features :
- Your hidden keywords idea is good. The implementation is weak though (See below). And it will silent too much messages, for example if I am using logging. AddSilentKeyword("start"), it will filter a log using "started" or "starting", which is really not what I would expect from a "keyword" filtering.
- The rest are very basic features. For example, as core of MQL are event driven, it's a must for a log system to avoid flooding the log with repeated same entry, which can happen easily with a Log() placed in a OnTick(), OnTimer() or OnChartEvent().
From a coding point of view :
- Your constructor and your Initialize() are duplicated code for the essential parts.
- Your IsMessageSilent() is using a loop check for each word of the m_silent_keywords[] and inside this loop you convert the 'keywords' to lower case. On each log ! It's really inefficient.
- Your class is hardly customizable, for example if I want to customize the log for ""File Name: " + __FILE__ + "\n", I will have to modify your code, or to derive a class and rewrite the Log() method entirely. There is the same problem for whatever custom change needed, for example using a BIN file.
- You define a Print() macro which will override the MQL built-in one. It's a very poor idea to force the user of your library to Print() in your log.
Conclusion :
Your library is a correct basic Logging library. It can be convenient for some beginners or coders lacking the time to build their own, providing them some easy to use logging features.
By no way, using the qualifier "Best" is justified. The features are correct but basic, and the implementation is of amateurish level.
I read your "Best Logging Class" name, which attracted my attention. "Best" is placing the level quite high, so I was curious to check that. I will avoid to talk about the details, as it's a freely distributed code which requires to be indulgent.
Usage and features :
- Your hidden keywords idea is good. The implementation is weak though (See below). And it will silent too much messages, for example if I am using logging. AddSilentKeyword("start"), it will filter a log using "started" or "starting", which is really not what I would expect from a "keyword" filtering.
- The rest are very basic features. For example, as core of MQL are event driven, it's a must for a log system to avoid flooding the log with repeated same entry, which can happen easily with a Log() placed in a OnTick(), OnTimer() or OnChartEvent().
From a coding point of view :
- Your constructor and your Initialize() are duplicated code for the essential parts.
- Your IsMessageSilent() is using a loop check for each word of the m_silent_keywords[] and inside this loop you convert the 'keywords' to lower case. On each log ! It's really inefficient.
- Your class is hardly customizable, for example if I want to customize the log for ""File Name: " + __FILE__ + "\n", I will have to modify your code, or to derive a class and rewrite the Log() method entirely. There is the same problem for whatever custom change needed, for example using a BIN file.
- You define a Print() macro which will override the MQL built-in one. It's a very poor idea to force the user of your library to Print() in your log.
Conclusion :
Your library is a correct basic Logging library. It can be convenient for some beginners or coders lacking the time to build their own, providing them some easy to use logging features.
By no way, using the qualifier "Best" is justified. The features are correct but basic, and the implementation is of amateurish level.
I realize that "best" might be an overstatement compared to your expectations. My intention was to share code that could be easily modified and understood by anyone. I hope, however, that I have made a small contribution to the community, and the class is available for everyone to use. I will soon proceed to optimize the code as you suggested.
Thanks again for the feedback.
2024.09.01 14:51:25.011 Logging (EURUSD,M30) File Name: Logging.mqh Function: string CDebugLogger::FormatLogEntry(LogLevel,string) 2024.09.01 14:51 Line: 276 [INFO] Script started successfully.
I think you have to use MACROS instead of class method to be able to emit the filename, function signature and line number where the log call occur.
I think you have to use MACROS instead of class method to be able to emit the filename, function signature and line number where the log call occur.
I've updated the code; please take a look. For me, it needs to be simple to use, so that it can standardize all programmers, both experienced and not, just as is done in other languages like Python. If you have any other ideas, please share them.
I read your "Best Logging Class" name, which attracted my attention. "Best" is placing the level quite high, so I was curious to check that. I will avoid to talk about the details, as it's a freely distributed code which requires to be indulgent.
Usage and features :
- Your hidden keywords idea is good. The implementation is weak though (See below). And it will silent too much messages, for example if I am using logging. AddSilentKeyword("start"), it will filter a log using "started" or "starting", which is really not what I would expect from a "keyword" filtering.
- The rest are very basic features. For example, as core of MQL are event driven, it's a must for a log system to avoid flooding the log with repeated same entry, which can happen easily with a Log() placed in a OnTick(), OnTimer() or OnChartEvent().
From a coding point of view :
- Your constructor and your Initialize() are duplicated code for the essential parts.
- Your IsMessageSilent() is using a loop check for each word of the m_silent_keywords[] and inside this loop you convert the 'keywords' to lower case. On each log ! It's really inefficient.
- Your class is hardly customizable, for example if I want to customize the log for ""File Name: " + __FILE__ + "\n", I will have to modify your code, or to derive a class and rewrite the Log() method entirely. There is the same problem for whatever custom change needed, for example using a BIN file.
- You define a Print() macro which will override the MQL built-in one. It's a very poor idea to force the user of your library to Print() in your log.
Conclusion :
Your library is a correct basic Logging library. It can be convenient for some beginners or coders lacking the time to build their own, providing them some easy to use logging features.
By no way, using the qualifier "Best" is justified. The features are correct but basic, and the implementation is of amateurish level.
As for the ability to silence individual words, I believe an efficient way is simply to write 'start ', including a space or another character. Ultimately, as with other languages, configuring the logs makes sense if done in the Init . As mentioned, it needs to be simple so that it's easily adoptable by everyone. If you think anything else needs to be added, feel free to write it down, and I'll try to add the code when I have time. Regarding the 'Print' function, everyone is free to comment it out if they wish.
I'm available for any further changes!
Thank you for your reply. I'm currently using your MQL Plus Enhanced Debugging Support library to print logs. However, sometimes it prints a large amount of repetitive logs, and I don't have a method to resolve this issue at the moment. The solution you suggested is one approach, and I'll try it when I have time. It requires careful design of the logging system.
Thank you for your reply. I'm currently using your MQL Plus Enhanced Debugging Support library to print logs. However, sometimes it prints a large amount of repetitive logs, and I don't have a method to resolve this issue at the moment. The solution you suggested is one approach, and I'll try it when I have time. It requires careful design of the logging system.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Best Logging Class for both MQL4 and MQL5:
The CDebugLogger class is a flexible and comprehensive logging utility designed for use in MQL4/5 environments. It allows developers to log messages at various levels of importance (INFO, WARNING, ERROR, DEBUG) with options to include timestamps, function signatures, file names, and line numbers in the log entries. The class supports logging to both the console and files, with the ability to save logs in a common folder and in CSV format. Additionally, it offers functionality to silence logs based on specific keywords, ensuring that sensitive information is not logged. This class is ideal for developers looking to implement robust logging mechanisms in their MQL4/5 applications, with customizable features that cater to a wide range of debugging and monitoring needs.
Author: VitalDefender Inc.