summaryrefslogtreecommitdiff
path: root/lib/textui/log.go
blob: cee51db4c93f3fa2e3aef05353d3a380479a27c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
}