However in VSCode the default logger is VSCodeServer.VSCodeLogger and when I try to set it back it freeze and I need to kill Julia (I have tried to deepcopy it, but no changes):
Heh, this is an interesting edge case. Your code is assuming that old_logger was a global logger previously, but that’s not actually the case – in VS Code, user code is evaluated in a with_logger(VSCodeLogger()) context. The more correct thing here would be old_logger = Logging.global_logger(), which does work.
Still I haven’t understood why current_logger() doesn’t work… the idea is I don’t know which is the Logger used, I set the current used in a variable, I set the current logger to NullLogger() and then I set it back to whatever it was before using the saved variable…
with_logger(VSCodeLogger()) do
eval(user_code)
end
without modifying the global logger at all. current_logger for your user_code will be VSCodeLogger, but global_logger is still the default ConsoleLogger. VSCodeLogger will forward all log messages it cannot handle to the global_logger, which causes a stack overflow if it’s also set to VSCodeLogger.
The issue with your code is that you’re reading “local” state and setting global state.
There is no function in Julia to set the local/current logger instead of setting the global one, right? (I have tried current_logger(logger) but of course it doesn’t exist )