summaryrefslogtreecommitdiff
path: root/lib/textui/log.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/textui/log.go')
-rw-r--r--lib/textui/log.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/textui/log.go b/lib/textui/log.go
new file mode 100644
index 0000000..cee51db
--- /dev/null
+++ b/lib/textui/log.go
@@ -0,0 +1,33 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package textui
+
+import (
+ "github.com/datawire/dlib/dlog"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/pflag"
+)
+
+type LogLevelFlag struct {
+ logrus.Level
+}
+
+var _ pflag.Value = (*LogLevelFlag)(nil)
+
+// Type implements pflag.Value.
+func (lvl *LogLevelFlag) Type() string { return "loglevel" }
+
+// Type implements pflag.Value.
+func (lvl *LogLevelFlag) Set(str string) error {
+ var err error
+ lvl.Level, err = logrus.ParseLevel(str)
+ return err
+}
+
+func NewLogger(lvl logrus.Level) dlog.Logger {
+ logger := logrus.New()
+ logger.SetLevel(lvl)
+ return dlog.WrapLogrus(logger)
+}