Libraries: Logify - Library for log management

 

Logify - Library for log management:

Logify is a logging library for MQL designed to simplify debugging, tracking, and monitoring of EAs and indicators. It provides structured, customizable, and organized logs directly on the chart or in the terminal, with support for log levels, flexible formats, and multiple handlers. A lightweight, elegant solution that is easy to integrate into your MQL projects.

Author: joaopedrodev

 
Excellent breakdown,s " Concerning basic fundamentals, providing supportive Acknowledgement, 👏 👌, Proceeding Rectified critical explanations! 
 

Hi, I put in a wrapper on the logify class to store and it's working fine when I test in in script.
however when I tried running Logify on strategy test on strategy test .. it doesn't work. It wouldn't store the logs into sqllite database

this is my class wrapper :

#include "Logify.mqh"

// include guard
#ifndef h_logifydb
#define h_logifydb

// Logs to SQLite database
// 5 Event
// Debug, Info, Alert, Error, Fatal

class CLogifyDB: public CLogify
{

protected:

   CLogifyHandlerDatabase *handler_database;
   

public :

   CLogifyDB();
   
   void CheckLogifyDB();

};

CLogifyDB::CLogifyDB(void): CLogify(){

   
   MqlLogifyHandleDatabaseConfig m_config;
   m_config.directory = "db";
   m_config.base_filename = "logs";
   m_config.messages_per_flush = 5;
   
   //--- Handler Database
   handler_database = new CLogifyHandlerDatabase();
   handler_database.SetConfig(m_config);
   handler_database.SetLevel(LOG_LEVEL_DEBUG);
   handler_database.SetFormatter(new CLogifyFormatter("hh:mm:ss","{date_time} [{levelname}] {msg}"));
   
   //--- Add handler in base class
   this.AddHandler(handler_database);
   this.CheckLogifyDB();
   
}

void CLogifyDB::CheckLogifyDB(void){

   int dbHandle = DatabaseOpen("db\\logs.sqlite", DATABASE_OPEN_READWRITE | DATABASE_OPEN_CREATE);
   if(dbHandle == INVALID_HANDLE)
     {
      Print("[ERROR] [" + TimeToString(TimeCurrent()) + "] Unable to open database (Error Code: " + IntegerToString(GetLastError()) + ")");
      return;
     }
   Print("[INFO] Database connection opened successfully.");

   if(!DatabaseTableExists(dbHandle, "logs"))
     {
      string createTableSQL =
         "CREATE TABLE logs ("
         "id INTEGER PRIMARY KEY AUTOINCREMENT,"   // Auto-incrementing unique ID
         "formated TEXT,"                           // Formatted log message
         "levelname TEXT,"                          // Log level name (INFO, ERROR, etc.)
         "msg TEXT,"                                // Main log message
         "args TEXT,"                               // Additional arguments/details
         "timestamp BIGINT,"                        // Timestamp of the log event
         "date_time DATETIME,"                      // Human-readable date and time
         "level BIGINT,"                            // Log level as an integer
         "origin TEXT,"                             // Module or component name
         "filename TEXT,"                           // Source file name
         "function TEXT,"                           // Function where the log was recorded
         "line BIGINT);";                           // Line number in the source code

      DatabaseExecute(dbHandle, createTableSQL);
      Print("[INFO] 'logs' table created successfully.");
     }
     
      DatabaseExecute(dbHandle,"VACUUM");
      DatabaseClose(dbHandle);

}

#endif 
 
DebblieLogan #Hi, I put in a wrapper on the logify class to store and it's working fine when I test in in script. however when I tried running Logify on strategy test on strategy test .. it doesn't work. It wouldn't store the logs into sqllite database ... this is my class wrapper :
My guess is: Please read the documentation on DatabaseOpen, and understand the File-Sandbox of MT5.

Your db is being stored where you are not expecting it.
 

Hi Dominik,

Thanks for answering. I think the location is fine because when I use the MQL5 script to test the 
wrapper to Logify. It's working fine (stores data into sqllite). But when I use it in my expert and run it through strategy tester
it's not storing any log. It's calling the logify class function fine but it's just not storing the data.

[Deleted]  
@DebblieLogan #Thanks for answering. I think the location is fine because when I use the MQL5 script to test the wrapper to Logify. It's working fine (stores data into sqllite). But when I use it in my expert and run it through strategy tester it's not storing any log. It's calling the logify class function fine but it's just not storing the data.

In the Strategy Tester, files are stored in the tester's folder, not in the usual location. This is not mentioned in the DatabaseOpen documentation, but it is in the FileOpen documentation.

The file is opened in the folder of the client terminal in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals.
Documentation on MQL5: File Functions / FileOpen
Documentation on MQL5: File Functions / FileOpen
  • www.mql5.com
The function opens the file with the specified name and flag. Parameters file_name [in]  The name of the file can contain subfolders. If the...
 

Dear @joaopedrodev, thank you very much for sharing this brilliant project to us. It's very useful and I have learned a lot when I read all regarding articles and all the code. Can you make the class private members from private to protected if it's not have to be private? I don't want to change the original code and use class inheritance to modify or add new features. E.g. to set date format from builder, emit log with origin filter, add a handler for mobile notification..... The private members make inheritance fail but protected can work.

If you don't want to modify them or the project has been closed, can you please let me know and I will not wait. Whatever, THANK YOU VERY MUCH.

joaopedrodev - Trader's profile
joaopedrodev - Trader's profile
  • 2025.09.22
  • www.mql5.com
Trader's profile