From 7699c3225855fbaa3cf6df8f1bb4bd3c6a9674c4 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Wed, 2 Mar 2022 18:03:08 +0800 Subject: [PATCH] client: only log when logger is non-nil --- client/log.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client/log.go b/client/log.go index f0299d2f..3aa6a1e4 100644 --- a/client/log.go +++ b/client/log.go @@ -13,21 +13,31 @@ func (c *QQClient) SetLogger(logger Logger) { } func (c *QQClient) info(msg string, args ...any) { - c.logger.Info(msg, args...) + if c.logger != nil { + c.logger.Info(msg, args...) + } } func (c *QQClient) warning(msg string, args ...any) { - c.logger.Warning(msg, args...) + if c.logger != nil { + c.logger.Warning(msg, args...) + } } func (c *QQClient) error(msg string, args ...any) { - c.logger.Error(msg, args...) + if c.logger != nil { + c.logger.Error(msg, args...) + } } func (c *QQClient) debug(msg string, args ...any) { - c.logger.Debug(msg, args...) + if c.logger != nil { + c.logger.Debug(msg, args...) + } } func (c *QQClient) dump(msg string, data []byte, args ...any) { - c.logger.Dump(data, msg, args...) + if c.logger != nil { + c.logger.Dump(data, msg, args...) + } }