Standard library / log

log.Logger.Panic()

Write a message then panic. This example recovers to demonstrate the panic; do not use panic for routine errors. Expected stdout: 'true\nhello\n'.

Formal Syntax & Structure

go syntaxgo
func (l *Logger) Panic(v ...any)

Parameters & Attributes

NameTypeDescription
v...anyValues to log or convert.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "log")
func main() {  var b bytes.Buffer  l := log.New(&b, "", 0)  defer func() { fmt.Println(recover() != nil); fmt.Print(b.String()) }()  l.Panic("hello")}
Go Reference