github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/logger/logger_test.go (about)

     1  // Copyright © 2022 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package logger
    16  
    17  import (
    18  	"fmt"
    19  	"sync"
    20  	"testing"
    21  	"time"
    22  
    23  	"github.com/sirupsen/logrus"
    24  )
    25  
    26  func TestLogger_Print(t *testing.T) {
    27  	if err := Init(LogOptions{
    28  		LogToFile:    false,
    29  		Verbose:      true,
    30  		DisableColor: false,
    31  	}); err != nil {
    32  		panic(fmt.Sprintf("failed to init logger: %v\n", err))
    33  	}
    34  
    35  	wg := &sync.WaitGroup{}
    36  	for i := 0; i < 5; i++ {
    37  		logrus.Info("start to test log")
    38  		for j := 0; j < 5; j++ {
    39  			wg.Add(1)
    40  			go func(x int) {
    41  				time.Sleep(1 * time.Second)
    42  				logrus.Debugf("i am the true entry %d", x)
    43  				wg.Done()
    44  			}(j)
    45  		}
    46  		wg.Wait()
    47  	}
    48  }