SkyAPM / go2sky

Distributed tracing and monitor SDK in Go for Apache SkyWalking APM
https://skywalking.apache.org/
Apache License 2.0
448 stars 123 forks source link

Add Log Interface #147

Closed arugal closed 2 years ago

arugal commented 2 years ago

Background

Now GRPCReporter can only use log.Logger to output logs, but there are many good log libraries, such as zap, logrus, I think we should design a logging interface and let the user decide which one to use.

Design

type Log interface {
    // Info logs to the INFO log.
    Info(args ...interface{})
    // Infof logs to the INFO log.
    Infof(format string, args ...interface{})
    // Warning logs to the WARNING and INFO logs.
    Warn(args ...interface{})
    // Warningf logs to the WARNING and INFO logs.
    Warnf(format string, args ...interface{})
    // Error logs to the ERROR, WARNING, and INFO logs.
    Error(args ...interface{})
    // Errorf logs to the ERROR, WARNING, and INFO logs.
    Errorf(format string, args ...interface{})
}

Use Case

    logger := log.New(os.Stderr, "go2sky", log.LstdFlags)

    reporter, _ := NewGRPCReporter("127.0.0.1:11800", WithLogger(logger))
    logger, _ := zap.NewProduction()
    defer logger.Sync() // flushes buffer, if any
    sugar := logger.Sugar()

    reporter, _ := NewGRPCReporter("127.0.0.1:11800", WithLog(sugar))
    logger := logrus.New()

    reporter, _ := NewGRPCReporter("127.0.0.1:11800", WithLog(logger))
codecov-commenter commented 2 years ago

Codecov Report

Merging #147 (3848d35) into master (a12c5be) will increase coverage by 0.09%. The diff coverage is 35.71%.

:exclamation: Current head 3848d35 differs from pull request most recent head 40f8f27. Consider uploading reports for the commit 40f8f27 to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
+ Coverage   70.64%   70.73%   +0.09%     
==========================================
  Files          18       18              
  Lines         930      933       +3     
==========================================
+ Hits          657      660       +3     
  Misses        225      225              
  Partials       48       48              
Impacted Files Coverage Δ
reporter/grpc.go 56.14% <35.71%> (+0.58%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a12c5be...40f8f27. Read the comment docs.

wu-sheng commented 2 years ago

Could you introduce what is this? I can't see the update in readme doc.

arugal commented 2 years ago

Could you introduce what is this? I can't see the update in readme doc.

Description has been added for this PR