-
Notifications
You must be signed in to change notification settings - Fork 3
/
clientLog.go
37 lines (33 loc) · 973 Bytes
/
clientLog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package rocketmq5Kit
import (
rmq_client "github.com/apache/rocketmq-clients/golang/v5"
"github.com/richelieu-yang/chimera/v3/src/core/envKit"
"github.com/richelieu-yang/chimera/v3/src/core/pathKit"
"github.com/richelieu-yang/chimera/v3/src/core/strKit"
"github.com/richelieu-yang/chimera/v3/src/file/fileKit"
"os"
)
func setClientLog(path string) error {
if strKit.IsEmpty(path) {
// (1) 输出到控制台
if err := os.Setenv(rmq_client.ENABLE_CONSOLE_APPENDER, "true"); err != nil {
return err
}
} else {
// (2) 输出到日志文件
if err := fileKit.AssertNotExistOrIsFile(path); err != nil {
return err
}
dir := pathKit.ParentDir(path)
name := fileKit.GetFileName(path)
if err := envKit.SetEnvs(map[string]string{
rmq_client.ENABLE_CONSOLE_APPENDER: "false",
rmq_client.CLIENT_LOG_ROOT: dir,
rmq_client.CLIENT_LOG_FILENAME: name,
}); err != nil {
return err
}
}
rmq_client.ResetLogger()
return nil
}