how to get middleware exception log messages?

hi,
I added logging midleware on the xdata server like the following code.

//add logging
  LoggingMiddleware := TLoggingMiddleware.Create;
  LoggingMiddleware.FormatString := ':remoteaddr :method :url :statuscode - :responsetime ms :reqheaders';
  LoggingMiddleware.LogLevel := TLogLevel.Info;
  LoggingMiddleware.ExceptionLogLevel := TLogLevel.Error;
  LoggingMiddleware.LogExceptions := True;

  Module.AddMiddleware(LoggingMiddleware);

with the tokens I took

':remoteaddr :method :url :statuscode - :responsetime ms :reqheaders'.

is there a way i can get the exception message, if the server returns an error message?

raise EXDataHttpException.Create(403, ErrorMessage);

Thanks you

If an exception is raised and you set LogExceptions to True, the exception will be logged with a different format, specified by ExceptionFormatString property.

That is explained here: https://doc.tmssoftware.com/biz/sparkle/guide/middleware.html#logging-middleware

From the documentation:

ExceptionFormatString: string
Specifies the format string for the message to be logged when an exception happens during the request processing. In other words, if any exception occurs in the server during request processing, and LogExceptions property is True, the exception will be logged using this format. Different from FormatString property which has a specific format, the content of this property is just a simple string used by Delphi Format function.
Three parameters are passed to the Format function, in this order: The exception message, the exception class name and the log message itself. Default value is:
(%1:s) %0:s - %2:s

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.