-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to log program crashes to the system log? #192
Comments
For logs within the service you can of course log to a file. But afaik if the service itself crashes, Windows logs the message/error code to system events (Open Event Viewer). You can perhaps refactor your code to exit with specific error codes based on where the panic is happening and cross-check in system events. |
Based on my experience yesterday, I encountered a hard-to-debug problem where a panic occurred but wasn't logged to the event logs. Windows of course detected the crash, and logged the fact that the service crashed, but the panic itself (and associated stack trace) was never logged. All I got was this log from Windows:
When I ran the service interactively from a terminal, the actual error and panic was printed to stderr, but it appears Windows does not capture stdout/stderr from a service process. (Which makes sense; event logs are the defined way to log things for services, not stdout/stderr.) I'm not sure whether the correct solution is to perform a Either way, the current state of allowing panic logs to go silently unreported is a bad state of affairs. |
Hmmm, doing some further reading I found golang/go#42888 where it looks like the issue is more complex. Basically, In the upstream issue, they are looking at solving this inside the Go runtime (and/or |
I have a program that uses lots of goroutines, and I suspect that a rare panic is possible. This program runs as a service on Windows, and as far as I can tell that means you cannot access stderr to view the stacktrace when this happens (I'm not a Windows expert).
I've been investigating how to try and capture one of these crashes. Obviously the brute force approach would be to put recovers everywhere, but this program is very complex and the crash is rare. Is there a better way to track down the issue?
I've got two ideas right now, neither of which is ideal. The first is to do something equivalent to dup2 to redirect stderr to a file, and bypass the Windows service logs entirely. The second is to make the service program a dumb wrapper that spawns the real program as a child process, then reads its stderr and logs it.
The text was updated successfully, but these errors were encountered: