summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-08-06 18:04:14 +0700
committerShulhan <ms@kilabit.info>2021-08-06 18:04:14 +0700
commitf7a4706b9172b23c07bdbb3d1146c8c05d212412 (patch)
tree098a790211b4ebdec84077c99bf41c36b2c8ee22
parente17a2bbf4b5efcbeb26654db660455d284070450 (diff)
downloadpakakeh.go-f7a4706b9172b23c07bdbb3d1146c8c05d212412.tar.xz
lib/mlog: add function and method Panicf
The Panicf method is equal to Errf followed by panic. This signature follow the log.Panicf convention.
-rw-r--r--lib/mlog/mlog.go7
-rw-r--r--lib/mlog/multi_logger.go10
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/mlog/mlog.go b/lib/mlog/mlog.go
index e3339848..6626c048 100644
--- a/lib/mlog/mlog.go
+++ b/lib/mlog/mlog.go
@@ -77,6 +77,13 @@ func Outf(format string, v ...interface{}) {
}
//
+// Panicf is equal to Errf followed by panic.
+//
+func Panicf(format string, v ...interface{}) {
+ defaultMLog.Panicf(format, v...)
+}
+
+//
// PrintStack writes to error writers the stack trace returned by
// debug.Stack.
//
diff --git a/lib/mlog/multi_logger.go b/lib/mlog/multi_logger.go
index cdc2c4d8..14ed0ee3 100644
--- a/lib/mlog/multi_logger.go
+++ b/lib/mlog/multi_logger.go
@@ -120,6 +120,16 @@ func (mlog *MultiLogger) Outf(format string, v ...interface{}) {
}
//
+// Panicf is equal to Errf and followed by panic.
+//
+func (mlog *MultiLogger) Panicf(format string, v ...interface{}) {
+ mlog.Errf(format, v...)
+ mlog.Flush()
+ msg := fmt.Sprintf(format, v...)
+ panic(msg)
+}
+
+//
// PrintStack writes to error writers the stack trace returned by
// debug.Stack.
//