Tuesday, March 14, 2023
HomeGolangExactly how to reroute stderr to submit - Obtaining Assistance

Exactly how to reroute stderr to submit – Obtaining Assistance

I’m attempting to rediect standardout as well as standarderr to submit, I can reroute conventional bent on submit by overwriting

 os.Stdout = * os.File.

Yet when I’m attempting to do the very same with os.Stderr its not absorbing impact, mistakes as well as various other panics are still publishing in console.

Can you reroute stderr as well as stdout from any place you begin your go program as opposed to within the Go program? E.g.:

./ mygoprogram > >/ var/log/mygoprogram. stdout.log 2> >/ var/log/mygoprogram. stderr.log.

So I require to create a celebration program to automate this procedure?

I’m not stating it’s your only choice, simply that it appears like a far better choice than transforming os.Stdout and/or os.Stderr There may be some initialization in some bundle someplace that caches the worth of os.Stdout prior to you transform it; for instance:

 bundle "somepackage".

var someKindOfLogger = && logger {
author: os.Stderr,.
// ...

func logSomethingOnPanic() {
someKindOfLogger.WriteSomething()// makes use of someKindOfLogger.writer which is.
// the worth of os.Stderr prior to you altered it.
 bundle "major".

func major() {
os.Stderr = createStderrReplacementFile()// this does not assist since various other.
// init code currently cached the worth of os.Stderr someplace.

If you reroute stderr as well as stdout, there is no timing problem pertaining to transforming os.Stdout prior to or after it’s been cached someplace.


Most Popular

Recent Comments