From db8e0c69089295fa6c6df497fbde2550074c4221 Mon Sep 17 00:00:00 2001 From: kakaZhou719 <83740799+kakaZhou719@users.noreply.github.com> Date: Tue, 6 Dec 2022 16:47:14 +0800 Subject: [PATCH] bugfix: use right logger time format (#1907) --- pkg/cluster-runtime/hook.go | 14 ++++------- pkg/logger/formatter.go | 2 +- pkg/logger/logger_test.go | 48 +++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 pkg/logger/logger_test.go diff --git a/pkg/cluster-runtime/hook.go b/pkg/cluster-runtime/hook.go index 5e4e34b089b..4e9e8254ae9 100644 --- a/pkg/cluster-runtime/hook.go +++ b/pkg/cluster-runtime/hook.go @@ -26,19 +26,15 @@ import ( "strings" "github.com/sealerio/sealer/common" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - k8syaml "k8s.io/apimachinery/pkg/util/yaml" - "github.com/sealerio/sealer/pkg/env" + "github.com/sealerio/sealer/pkg/infradriver" v1 "github.com/sealerio/sealer/types/api/v1" + netUtils "github.com/sealerio/sealer/utils/net" "github.com/sealerio/sealer/utils/yaml" - "github.com/sirupsen/logrus" - - "github.com/sealerio/sealer/pkg/infradriver" - netUtils "github.com/sealerio/sealer/utils/net" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + k8syaml "k8s.io/apimachinery/pkg/util/yaml" ) const ( diff --git a/pkg/logger/formatter.go b/pkg/logger/formatter.go index 7ef26f62863..50580d99585 100644 --- a/pkg/logger/formatter.go +++ b/pkg/logger/formatter.go @@ -31,7 +31,7 @@ const ( ) const ( - defaultTimestampFormat = "2006-01-02 15:03:04" + defaultTimestampFormat = "2006-01-02 15:04:05" ) func getColorByLevel(level logrus.Level) int { diff --git a/pkg/logger/logger_test.go b/pkg/logger/logger_test.go new file mode 100644 index 00000000000..537123fe6a6 --- /dev/null +++ b/pkg/logger/logger_test.go @@ -0,0 +1,48 @@ +// Copyright © 2022 Alibaba Group Holding Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package logger + +import ( + "fmt" + "sync" + "testing" + "time" + + "github.com/sirupsen/logrus" +) + +func TestLogger_Print(t *testing.T) { + if err := Init(LogOptions{ + LogToFile: false, + Verbose: true, + DisableColor: false, + }); err != nil { + panic(fmt.Sprintf("failed to init logger: %v\n", err)) + } + + wg := &sync.WaitGroup{} + for i := 0; i < 5; i++ { + logrus.Info("start to test log") + for j := 0; j < 5; j++ { + wg.Add(1) + go func(x int) { + time.Sleep(1 * time.Second) + logrus.Debugf("i am the true entry %d", x) + wg.Done() + }(j) + } + wg.Wait() + } +}