summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2011-01-11 09:57:47 -0800
committerRob Pike <r@golang.org>2011-01-11 09:57:47 -0800
commitff681651f4d087488521ea5171bcd84a674be2b4 (patch)
tree75779b7d76f296abafaaec710f9bee9275f10903
parentb75e8200028368cade26f678e77d8749c1c3206d (diff)
downloadgo-ff681651f4d087488521ea5171bcd84a674be2b4.tar.gz
log: add methods for exit and panic
There were already functions for the standard logger; this just completes the set. R=rsc, adg CC=golang-dev http://codereview.appspot.com/3901043
-rw-r--r--src/pkg/log/log.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/pkg/log/log.go b/src/pkg/log/log.go
index f7176e8e5..d34af9e5e 100644
--- a/src/pkg/log/log.go
+++ b/src/pkg/log/log.go
@@ -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