github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/runtime/debug/example_monitor_test.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package debug_test
     6  
     7  // ExampleSetCrashOutput_monitor shows an example of using
     8  // [debug.SetCrashOutput] to direct crashes to a "monitor" process,
     9  // for automated crash reporting. The monitor is the same executable,
    10  // invoked in a special mode indicated by an environment variable.
    11  func ExampleSetCrashOutput_monitor() {
    12  	appmain()
    13  
    14  	// This Example doesn't actually run as a test because its
    15  	// purpose is to crash, so it has no "Output:" comment
    16  	// within the function body.
    17  	//
    18  	// To observe the monitor in action, replace the entire text
    19  	// of this comment with "Output:" and run this command:
    20  	//
    21  	//    $ go test -run=ExampleSetCrashOutput_monitor runtime/debug
    22  	//    panic: oops
    23  	//    ...stack...
    24  	//    monitor: saved crash report at /tmp/10804884239807998216.crash
    25  }