chore: enable more linter (#1557)

This commit is contained in:
Jan-Otto Kröpke
2024-08-10 22:05:33 +02:00
committed by GitHub
parent 27a3553dac
commit 9b02e4a0ea
87 changed files with 337 additions and 494 deletions

View File

@@ -70,7 +70,7 @@ func (l *eventlogLogger) Log(keyvals ...interface{}) error {
msg, err := syscall.UTF16PtrFromString(lb.buf.String())
if err != nil {
return fmt.Errorf("error convert string to UTF-16: %v", err)
return fmt.Errorf("error convert string to UTF-16: %w", err)
}
ss := []*uint16{msg, nil, nil, nil, nil, nil, nil, nil, nil}
@@ -104,7 +104,7 @@ func (l *eventlogLogger) putLoggerBuf(lb *loggerBuf) {
// PrioritySelector inspects the list of keyvals and selects an eventlog priority.
type PrioritySelector func(keyvals ...interface{}) Priority
// defaultPrioritySelector convert a kit/log level into a Windows Eventlog level
// defaultPrioritySelector convert a kit/log level into a Windows Eventlog level.
func defaultPrioritySelector(keyvals ...interface{}) Priority {
l := len(keyvals)

View File

@@ -20,14 +20,14 @@ import (
promlogflag "github.com/prometheus/common/promlog/flag"
)
// FileFlagName is the canonical flag name to configure the log file
// FileFlagName is the canonical flag name to configure the log file.
const FileFlagName = "log.file"
// FileFlagHelp is the help description for the log.file flag.
const FileFlagHelp = "Output file of log messages. One of [stdout, stderr, eventlog, <path to log file>]"
// AddFlags adds the flags used by this package to the Kingpin application.
// To use the default Kingpin application, call AddFlags(kingpin.CommandLine)
// To use the default Kingpin application, call AddFlags(kingpin.CommandLine).
func AddFlags(a *kingpin.Application, config *log.Config) {
config.Level = &promlog.AllowedLevel{}
a.Flag(promlogflag.LevelFlagName, promlogflag.LevelFlagHelp).

View File

@@ -33,7 +33,7 @@ func (f *AllowedFile) Set(s string) error {
case "eventlog":
f.w = nil
default:
file, err := os.OpenFile(s, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0200)
file, err := os.OpenFile(s, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o200)
if err != nil {
return err
}
@@ -42,7 +42,7 @@ func (f *AllowedFile) Set(s string) error {
return nil
}
// Config is a struct containing configurable settings for the logger
// Config is a struct containing configurable settings for the logger.
type Config struct {
promlog.Config
@@ -72,15 +72,17 @@ func New(config *Config) (log.Logger, error) {
return nil, fmt.Errorf("unsupported log.format %q", config.Format.String())
}
if config.File.s == "eventlog" {
switch {
case config.File.s == "eventlog":
w, err := goeventlog.Open("windows_exporter")
if err != nil {
return nil, err
}
l = eventlog.NewEventLogLogger(w, loggerFunc)
} else if config.File.w == nil {
case config.File.w == nil:
panic("logger: file writer is nil")
} else {
default:
l = loggerFunc(log.NewSyncWriter(config.File.w))
}