From 73b2b41e777614d7c372b9d92a90b5fbb68d05c0 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 10 Sep 2022 18:28:19 +0800 Subject: Replace all logger usages to custom logging.Logger. --- bilibili/client.go | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'bilibili/client.go') diff --git a/bilibili/client.go b/bilibili/client.go index 8097115..f72432a 100644 --- a/bilibili/client.go +++ b/bilibili/client.go @@ -5,11 +5,10 @@ This struct is a facade of all necessary Bilibili HTTP API wrappers. package bilibili import ( + "bilibili-livestream-archiver/logging" "context" - "log" "net" "net/http" - "os" ) const ( @@ -21,19 +20,12 @@ const ( type Bilibili struct { userAgent string http *http.Client - loggerCommon - ctx context.Context - netTypes []IpNetType + ctx context.Context + netTypes []IpNetType + logger logging.Logger } -func NewBilibiliWithContext(ctx context.Context, netTypes []IpNetType) Bilibili { - logger := loggerCommon{ - debug: log.New(os.Stderr, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile), - info: log.New(os.Stderr, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile), - warn: log.New(os.Stderr, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile), - error: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile), - } - +func NewBilibiliWithContext(ctx context.Context, netTypes []IpNetType, logger logging.Logger) Bilibili { var nets []IpNetType nets = append(nets, netTypes...) if len(nets) == 0 { @@ -47,19 +39,19 @@ func NewBilibiliWithContext(ctx context.Context, netTypes []IpNetType) Bilibili transport.DialContext, _ = np.NextNetworkType(dialer) return Bilibili{ - loggerCommon: logger, - userAgent: kUserAgent, - http: http.DefaultClient, - ctx: ctx, - netTypes: nets, + logger: logger, + userAgent: kUserAgent, + http: http.DefaultClient, + ctx: ctx, + netTypes: nets, } } -func NewBilibiliWithNetType(netTypes []IpNetType) Bilibili { +func NewBilibiliWithNetType(netTypes []IpNetType, logger logging.Logger) Bilibili { ctx := context.Background() - return NewBilibiliWithContext(ctx, netTypes) + return NewBilibiliWithContext(ctx, netTypes, logger) } -func NewBilibili() Bilibili { - return NewBilibiliWithNetType(nil) +func NewBilibili(logger logging.Logger) Bilibili { + return NewBilibiliWithNetType(nil, logger) } -- cgit v1.2.3