Watch how to download trading robots for free
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

Log4mql(mini) MT5 - library for MetaTrader 5

lippmaje

Views:
727
Rating:
votes: 4
Published:
2021.01.20 22:05
Updated:
2021.01.25 06:11
\MQL5\Include\
log4mqlm.mqh (40.44 KB) view

Log4mql(mini) - light header-only version of Log4mql that provides standardized logging.


Sample output MT5


Installation/Usage

  • Add log4mqlm.mqh to your Include folder.
  • View the sample code to get an overview of the usage.


    Inputs

    Log4mql(mini) requires only one input field. There is no logging to files.

    • Loglevel, supports Trace, Debug, Info, Warn, Error and Fatal

    Log4mql(mini) Inputs


      Message Pattern

      The message pattern will have a fixed format which corresponds to its appropriate severity level, according to below table.

       Severity Format
       Sample output
       Info (the commonly used default) %func: %msg
      OnInit:  Log level: TRACE
       Debug, Trace
      %func(%file:%line): %msg
      OnInit(log4mqlm_sample.mq5:72): initializing
       Warn
      WARN %func(%file:%line): %msg
      WARN SomeFunction(log4mqlm_sample.mq5:64): stoploss too tight
       Error
      ERROR %func(%file:%line): %msg
      optionally followed by: [, error %lasterr - %lasterrdesc]
      ERROR OnDeinit(log4mqlm_sample.mq5:85): open 'some file' failed,  error 5004 - Cannot open file
       Fatal FATAL ... as above
      FATAL  ...


      Functions

      Log4mql(mini) provides functions and preprocessor macros for logging, all macros are to be used like functions.

      Return type
      Function name
      Description
       bool
       PRINT (...)
       Prints its message if log level is set at least to INFO (= normal logging behavior).
       Supports up to 9 arguments - PRINT("1",2,etc) - if you need more, expand the templates.
       Returns true if message was logged, else false.
       bool
       PRINTF (string format,...)
       Like PRINT but prints a formatted message. Same rules as known from PrintFormat apply.
       bool
       WARN (...)
       WARNF (string format,...)
       Prints its message if log level is set at least to WARN.
       bool
       ERROR (...)
       ERRORF (string format,...)
       Prints its message if log level is at least ERROR. Adds _LastError description if set.
       bool
       FATAL (...)
       FATALF (string format,...)
       Like ERROR, but with termination. You should call ExpertRemove() or exit immediately otherwise after this.
       Example:
         if(step<MinStep) { FATALF("invalid step size: %f",step); ExpertRemove(); return; }
       bool
       DEBUG (...)
       DEBUGF (string format,...)
       Messages for DEBUG level.
       bool
       TRACE (...)
       TRACEF (string format,...)
       Messages for TRACE (more verbose than DEBUG, for function entries, calculations etc).



       string  L4mq.LastMessage()  Get the last message that has been logged.
       int  L4mq.LastLevel()  Get the severity level of the last logging event.
       int  L4mq.Level()  Get the severity level of the logger.
       string  L4mq.LevelAsString()  Get the severity level of the logger as string.
       void  L4mq.SetLevel(int)  Set the severity level for the logger.
       ulong  L4mq.SeqNr()  Get the sequence number of the last logged event.
       bool  L4mq.logged  true if the last event was logged.
           
       string  Log4mql::GetErrorDescription(int err)  Get the description of an error code like _LastError.
       string
       Log4mql::GetUninitReason(int reason)  Get the description of the uninit reason.
       string  Log4mql::LoglevelToString(int level)  Convert a log level to a descriptive string.


      Notes

      • As the functionality strives to be as simple as possible, there is no logging to files. You could implement some on your own if you want.
      • You are free to use this code in your work, however, if you share the source code you must not remove the copyright and license notice.
      • The full functionality of Log4mql is available here: https://www.mql5.com/en/code/31425 (MT4) or here: https://www.mql5.com/en/code/31452 (MT5)



      Spread Informer Spread Informer

      This EA collects information about the spread and shows the statistics on the chart. When the EA ends its working, it prints all statistics to the Journal, which can be useful for the Strategy Tester.

      selection sort - array sorting algorithm selection sort - array sorting algorithm

      an in-place comparison sorting algorithm

      Breakout Strength Meter - MT5 Breakout Strength Meter - MT5

      The breakout strength meter is a trading tool that is used to identify which currencies are the strongest to breakout, and which currencies are the weakest to breakout

      insertion sort - array sorting algorithm insertion sort - array sorting algorithm

      a simple sorting algorithm that people use to manually sort cards in a bridge hand