1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00
gocsaf/internal/options/log.go
2023-11-28 10:37:16 +01:00

34 lines
912 B
Go

// This file is Free Software under the MIT License
// without warranty, see README.md and LICENSES/MIT.txt for details.
//
// SPDX-License-Identifier: MIT
//
// SPDX-FileCopyrightText: 2023 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2023 Intevation GmbH <https://intevation.de>
package options
import (
"strings"
"golang.org/x/exp/slog"
)
// LogLevel implements a helper type to be used in configurations.
type LogLevel struct{ slog.Level }
// MarshalFlag implements [flags.Marshaler].
func (ll LogLevel) MarshalFlag() (string, error) {
t, err := ll.MarshalText()
return strings.ToLower(string(t)), err
}
// UnmarshalFlag implements [flags.Unmarshaler].
func (ll *LogLevel) UnmarshalFlag(value string) error {
var l slog.Level
if err := l.UnmarshalText([]byte(value)); err != nil {
return err
}
*ll = LogLevel{Level: l}
return nil
}