I am looking at the FMX built in logging support via the Log class which uses the IFMXLoggingService to write events. I have found info for the log file location in iOS and Android but unable to find anything on Windows (8.1).
Does anyone know which specific log file this service writes to? and is this able to be changed in code or otherwise?
Thanks
If you look at the sources you will find the implementation at FMX.Platform.Win.TPlatformWin.Log
:
procedure TPlatformWin.Log(const Fmt: string; const Params: array of const);
begin
OutputDebugString(PChar(Format(Fmt, Params)));
end;
OutputDebugString()
does not send messages to any log file at all. It logs to the debugger's built-in event log, when the app is running inside the debugger. When the app is running outside of the debugger, third-party tools like SysInternal DebugView can capture these messages.
If you want to use a custom logger, write a class that implements the IFMXLoggingService
interface and register it with FMX at runtime:
type
TMyLoggingService = class(TInterfacedObject, IFMXLoggingService)
public
procedure Log(const Format: string; const Params: array of const);
end;
procedure TMyLoggingService.Log(const Format: string; const Params: array of const);
begin
// do whatever you want...
end;
var
MyLoggingService : IFMXLoggingService;
begin
MyLoggingService := TMyLoggingService.Create;
// if a service is already registered, remove it first
if TPlatformServices.Current.SupportsPlatformService( IFMXLoggingService ) then
TPlatformServices.Current.RemovePlatformService( IFMXLoggingService );
// now register my service
TPlatformServices.Current.AddPlatformService( IFMXLoggingService, MyLoggingService );
end;
This is mentioned in Embarcadero's documentation:
You can use TPlatformServices.AddPlatformService and TPlatformServices.RemovePlatformService to register and unregister platform services, respectively.
For example, you can unregister one of the built-in platform services and replace it with a new implementation of the platform service that is tailored to fit your needs.