For newer Delphi versions, with OSX and Android support, is there a platform-independent way to detect if Writeln to Output can be used safely?
The documentation for Output contains a note saying
Most processes do not have a standard output file, and writing to Output raises an error. Delphi programs have a standard output file if they are linked as console applications.
My primary goal is to have a platform-independent fallback for logging, but to avoid any OS errors which can arise when no console (stdout) is present.
For example: would it be sufficient to check IsConsole like so:
procedure Log(const Msg: string);
begin
if LoggingFrameworkAvailable then
begin
// use the logging framework to output the log message
end if System.IsConsole then
begin
// fallback to stdout logging
WriteLn(Msg);
end;
end;
So the question could be rephrased: "Can a Delphi application always safely use Output if IsConsole is True?".
As it is meant to be a fallback log method, it would be fine for me if log messages are "invisible" (redirected to /dev/null), as long as the code is guaranteed to run cross-platform without errors.
If yes, does this code also work safely with Free Pascal? (See Can a Windows GUI program written in Lazarus create a console and write to it at runtime?)