FAQ
Hello Folks,

I have program that programmatically changes stderr to write to a file, if
an error log has been defined in it's config file. That works fine, however
I have found that a runtime panic does not write to the error file. The
code I used follows:

errorLog, err := os.OpenFile(fqFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE,
0666)
exitOnError(err)

os.Stderr.Close()

// I have tried the following variations:

// os.Stderr = errorLog

// and...
stderrFD := int(errorLog.Fd())
err = syscall.Dup2(2, stderrFD)
exitOnError(err)


I have reviewed the documentation and tried searching on "golang panic" and
other terms, but have not found any useful information. Any help would be
much appreciated.

Thanks,

Daryl

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ian Lance Taylor at Sep 24, 2013 at 7:41 pm

    On Tue, Sep 24, 2013 at 12:30 PM, Daryl Williams wrote:

    I have program that programmatically changes stderr to write to a file, if
    an error log has been defined in it's config file. That works fine, however
    I have found that a runtime panic does not write to the error file.
    Unfortunately on Unix systems panic always writes directly to file
    descriptor 2. Changing os.Stderr will not affect that. You could use
    the system dependent Dup2 call, as you tried, only you would have to
    use

    syscall.Dup2(stderrFD, 2)

    to change descriptor 2 to be your file.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Daryl Williams at Sep 24, 2013 at 7:48 pm
    Thanks Lance, I just tried your suggestion and it worked great! I guess
    that still leaves me to figure out how to do this on Windows...

    Best Regards,

    Daryl

    On 9/24/13 12:41 PM, Ian Lance Taylor wrote:
    On Tue, Sep 24, 2013 at 12:30 PM, Daryl Williams
    wrote:
    I have program that programmatically changes stderr to write to a file, if
    an error log has been defined in it's config file. That works fine, however
    I have found that a runtime panic does not write to the error file.
    Unfortunately on Unix systems panic always writes directly to file
    descriptor 2. Changing os.Stderr will not affect that. You could use
    the system dependent Dup2 call, as you tried, only you would have to
    use

    syscall.Dup2(stderrFD, 2)

    to change descriptor 2 to be your file.

    Ian
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 24, '13 at 7:31p
activeSep 24, '13 at 7:48p
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase