TMS Logger suggestions

(Tag "workflow" is because I MUST select one, and TMS Logging isn't available)

I have begun using your TMS Logging system and have a few suggestions:

  1. You should make it possible for the user to override the resource strings you define in TMSLoggingUtils without having to resort to resources (but still maintain compatibilty with this for users who do want it). One was I usually do this is like this:
resourcestring
  resTMSLoggerTimeStamp = 'Date / Time';
  resTMSLoggerMemoryUsage = 'Memory usage';
  resTMSLoggerProcessID = 'Process ID';
  resTMSLoggerThreadID = 'Thread ID';
  resTMSLoggerLogLevel = 'Level';
  resTMSLoggerName = 'Name';
  resTMSLoggerValue = 'Value';
  resTMSLoggerType = 'Type';

VAR
  sTMSLoggerTimeStamp,
  sTMSLoggerMemoryUsage,
  sTMSLoggerProcessID,
  sTMSLoggerThreadID,
  sTMSLoggerLogLevel,
  sTMSLoggerName,
  sTMSLoggerValue,
  sTMSLoggerType : STRING;

INITIALIZATION

  sTMSLoggerTimeStamp := resTMSLoggerTimeStamp;
  sTMSLoggerMemoryUsage := resTMSLoggerMemoryUsage;
  sTMSLoggerProcessID := resTMSLoggerProcessID;
  sTMSLoggerThreadID := resTMSLoggerThreadID;
  sTMSLoggerLogLevel := resTMSLoggerLogLevel;
  sTMSLoggerName := resTMSLoggerName;
  sTMSLoggerValue := resTMSLoggerValue;
  sTMSLoggerType := resTMSLoggerType;

end.

ie. let the resource strings be the default values, that is then assigned to ordinary STRING variables (which then can be overridden programmatically by the user).

  1. Have some way to allow the user to override the textual representation of the various log levels. I have so far done it this way:
TYPE
  TLogLevelToString = REFERENCE TO FUNCTION(Level : TTMSLoggerLogLevel) : STRING;

  TTMSLoggerLogLevelHelper = record helper for TTMSLoggerLogLevel
    function ToString: string;
    FUNCTION AsString : STRING;
  end;

VAR
  LogLevelToString : TLogLevelToString;

{ TTMSLoggerLogLevelHelper }

function TTMSLoggerLogLevelHelper.ToString: string;
begin
  IF Assigned(LogLevelToString) THEN
    Result:=LogLevelToString(Self)
  ELSE
    Result:=AsString
END;

FUNCTION TTMSLoggerLogLevelHelper.AsString : STRING;
  BEGIN
    Result := GetEnumName(TypeInfo(TTMSLoggerLogLevel), Integer(Self));
  END;

This will allow you to override the conversion by assigning an (anonymous) method to the LogLevelToString reference. The reason I have saved the old way in .AsString is that in method

class function TTMSLoggerUtils.GetHTMLFormattedMessage

you have the following code, where you need the Original conversion (for the class name) and the translated version (for the textual output) at the same time:

      if loLogLevel in AOutputInformation.Outputs then
      begin
        if (AOutputInformation.LogLevel <> TTMSLoggerLogLevel.All) then
          msg := msg + dws + '<td><div class=''logger'+AOutputInformation.LogLevel.AsString.ToLower+'''>'+AOutputInformation.LogLevel.ToString+'</div></td>' + dwe + #13#10
        else
          msg := msg + dws + '<td></td>' + dwe + #13#10;
      end;

You may of course have your own way to implement these requests - the above code is just an example :slight_smile: .