]> Cypherpunks repositories - gostls13.git/commitdiff
log: add methods for exit and panic
authorRob Pike <r@golang.org>
Tue, 11 Jan 2011 17:57:47 +0000 (09:57 -0800)
committerRob Pike <r@golang.org>
Tue, 11 Jan 2011 17:57:47 +0000 (09:57 -0800)
There were already functions for the standard logger;
this just completes the set.

R=rsc, adg
CC=golang-dev
https://golang.org/cl/3901043

src/pkg/log/log.go

index f7176e8e5ca88fa9cba2605502e98082ed8a82bf..d34af9e5e4548406a32b5eb3f6f14df95535253f 100644 (file)
@@ -164,6 +164,45 @@ func (l *Logger) Print(v ...interface{}) { l.Output(2, fmt.Sprint(v...)) }
 // Arguments are handled in the manner of fmt.Println.
 func (l *Logger) Println(v ...interface{}) { l.Output(2, fmt.Sprintln(v...)) }
 
+// Exit is equivalent to l.Print() followed by a call to os.Exit(1).
+func (l *Logger) Exit(v ...interface{}) {
+       l.Output(2, fmt.Sprint(v...))
+       os.Exit(1)
+}
+
+// Exitf is equivalent to l.Printf() followed by a call to os.Exit(1).
+func (l *Logger) Exitf(format string, v ...interface{}) {
+       l.Output(2, fmt.Sprintf(format, v...))
+       os.Exit(1)
+}
+
+// Exitln is equivalent to l.Println() followed by a call to os.Exit(1).
+func (l *Logger) Exitln(v ...interface{}) {
+       l.Output(2, fmt.Sprintln(v...))
+       os.Exit(1)
+}
+
+// Panic is equivalent to l.Print() followed by a call to panic().
+func (l *Logger) Panic(v ...interface{}) {
+       s := fmt.Sprint(v...)
+       l.Output(2, s)
+       panic(s)
+}
+
+// Panicf is equivalent to l.Printf() followed by a call to panic().
+func (l *Logger) Panicf(format string, v ...interface{}) {
+       s := fmt.Sprintf(format, v...)
+       l.Output(2, s)
+       panic(s)
+}
+
+// Panicln is equivalent to l.Println() followed by a call to panic().
+func (l *Logger) Panicln(v ...interface{}) {
+       s := fmt.Sprintln(v...)
+       l.Output(2, s)
+       panic(s)
+}
+
 // SetOutput sets the output destination for the standard logger.
 func SetOutput(w io.Writer) {
        std.out = w