From 225e60d8b46edcdaef9c5f5faa3c7e825239af40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flc=E3=82=9B?= Date: Thu, 16 Nov 2023 16:26:58 +0800 Subject: [PATCH] fix(syslog): the syslog service cannot be started properly because it is unstable (#31) --- log/syslog/syslog.go | 16 ++++++++-------- log/syslog/syslog_test.go | 13 ++++++------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/log/syslog/syslog.go b/log/syslog/syslog.go index f8b9d921..a1235a82 100644 --- a/log/syslog/syslog.go +++ b/log/syslog/syslog.go @@ -23,19 +23,19 @@ type Logger struct { var _ log.Logger = (*Logger)(nil) -func New(config *Config) (*Logger, error) { - s := &Logger{ +func New(config *Config) *Logger { + return &Logger{ config: config, } - - if err := s.connect(); err != nil { - return nil, err - } - - return s, nil } func (l *Logger) Log(level log.Level, keyvals ...interface{}) error { + if l.conn == nil { + if err := l.connect(); err != nil { + return err + } + } + if len(keyvals) == 0 { return nil } diff --git a/log/syslog/syslog_test.go b/log/syslog/syslog_test.go index 4bd1f806..c7895d33 100644 --- a/log/syslog/syslog_test.go +++ b/log/syslog/syslog_test.go @@ -3,26 +3,25 @@ package syslog import ( + "runtime" "testing" "github.com/go-kratos/kratos/v2/log" ) func TestSyslogLogger(t *testing.T) { - t.Skip("skip syslog test") + if runtime.GOOS == "windows" { + t.Skip("skip syslog test") + } - logger, err := New(&Config{ + logger := New(&Config{ Network: "udp", Addr: "192.168.8.92:30732", Tag: "test", }) defer logger.Close() - if err != nil { - t.Fatal(err) - } - - err = logger.Log(log.LevelDebug, "test", "test") + err := logger.Log(log.LevelDebug, "test", "test") if err != nil { t.Fatal(err) }