github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/netlog/test/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"strings"
     7  	"time"
     8  
     9  	"github.com/binkynet/BinkyNet/netlog"
    10  	"github.com/rs/zerolog"
    11  )
    12  
    13  func main() {
    14  	_, err := netlog.NewLogReceiver(func(msg netlog.NetLogMessage) {
    15  		fmt.Printf("Level=%s Address=%s Msg=%s\n", msg.Level.String(), msg.Address, strings.TrimSpace(string(msg.Message)))
    16  	})
    17  	if err != nil {
    18  		log.Fatalf("NewLogReceiver failed: %s\n", err)
    19  	}
    20  
    21  	netLog, err := netlog.NewLogger()
    22  	if err != nil {
    23  		log.Fatalf("NewLogger failed: %s\n", err)
    24  	}
    25  	log := zerolog.New(zerolog.ConsoleWriter{Out: netLog}).With().Timestamp().Logger()
    26  
    27  	log.Debug().Msg("Hello logger")
    28  	for i := 0; i < 50; i++ {
    29  		go func(i int) {
    30  			log.Info().Int("i", i).Msgf("Message %d", i)
    31  		}(i)
    32  	}
    33  	time.Sleep(time.Second * 5)
    34  }