Can I invoke a macro with a string parameter in the form a+b+c ?

 

Hello, here it's hard to understand for me why the compiler generate this error and how I can fix it:

#define __Log__(_msg) {StringConcatenate(_msg,"<session_id>\t",_msg);   \
                      Print(_msg);}

int OnInit()
{   
   string fn = __FUNCTION__, msg=" started"; 
   __Log__(fn+msg); // compilation error : "+" - variable expected

   return (INIT_FAILED);
}

many thanks to everyone who will help!

 
#define __Log__(_msg) Print("<session_id>\t",_msg)
 

great lippmaje tanks again, It do a great job also with Filewrite :

#define __Log__(msg_log_level, msg) if(msg_log_level<=Log::log_level){                                              \
                                      if(Log::journal) Print(EnumToString(msg_log_level),"\t",msg);                 \ 
                                      if(Log::fh!=INVALID_HANDLE)                                                   \
                                        FileWrite(Log::fh,TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS)+"\t"+_Symbol+"\t"+msg);}
lippmaje
lippmaje
  • www.mql5.com
How to display the error text of a runtime error, MQL 4/5 compliant:   #ifdef __MQL5__ #include #else #include #endif   int OnInit ()   {    ResetLastError ();    // do something that might set an error    if ( _LastError )      {        Print ( "error: " , _LastError , " " ,ErrorDescription( _LastError )); // error: 4802 Indicator cannot be...
 

Good. Suggestion:

#define __Log__(msg_log_level, msg) Log::LogMsg(msg_log_level, __FUNCTION__, msg)

#define __Log1__(msg) __Log__(1, msg)

#define __Log2__(msg) __Log__(2, msg)

static void Log::LogMsg(int level, string func, string msg)
  {
   if(level<=Log::log_level)
     {
      if(Log::journal) Print(EnumToString(level),"\t",func,"\t",msg);
      if(Log::fh!=INVALID_HANDLE)
         FileWrite(Log::fh,TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS)+"\t"+_Symbol+"\t"+func+"\t"+msg);
     }
  }
Reason: