Avoid double stacktrace when logging error

I have a long running application with custom loggers set up, and when an error is thrown, I want to log that nicely with @error. This is done in a catch block, and works well. Since @error does not throw an error itself, I added rethrow(), because I want a non-zero exit code. What I don’t like however is that I then get two stacktraces in the terminal.

function f()
    try
        error("oh no")
    catch e
        @error "Something went wrong" exception = (e, catch_backtrace())
        rethrow()
    end
end

f()
┌ Error: Something went wrong
│   exception =
│    oh no
│    Stacktrace:
│     [1] error(s::String)
│       @ Base .\error.jl:33
│     [2] f()
│       @ Main C:\tmp\err\err.jl:3
│     [3] top-level scope
│       @ C:\tmp\err\err.jl:10
│     [4] include(mod::Module, _path::String)
│       @ Base .\Base.jl:418
│     [5] exec_options(opts::Base.JLOptions)
│       @ Base .\client.jl:292
│     [6] _start()
│       @ Base .\client.jl:495
└ @ Main C:\tmp\err\err.jl:5
ERROR: LoadError: oh no
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] f()
   @ Main C:\tmp\err\err.jl:3
 [3] top-level scope
   @ C:\tmp\err\err.jl:10
in expression starting at C:\tmp\err\err.jl:10

Is there a way to avoid swallowing the exception but not have it printed a second time? Of course exit(1) instead of rethrow() would work but I don’t want it to quit julia.

In my custom logging I use the TeeLogger from LoggingExtras.jl to log simultaneously to the terminal and a file.

Now I attach an _id = :my_id to this particular @error, and use EarlyFilteredLogger to filter out that ID for the terminal, but not for the logfile. Combined with this trick I then get a nice stacktrace from @error in my logfile, and a single stacktrace from rethrow() in the terminal. That seems like an acceptable workaround, though if people have other ideas I’d like to hear them.