This is expected behavior - you'd get the exact same output if you had written that code yourself in the script console:
The script console is a bit of a one-off unicorn; it manually "wraps" the stdout
and stderr
buffers for code executing inside itself. Logging should be considered a "side channel" for information capture - if you want something to be visible to the caller, your options are to return it directly or write it to stdout
(which itself has caveats for gateway scope). No free lunch, unfortunately.