rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vongosl...@apache.org
Subject [rocketmq-client-go] branch master updated: support set log output path (#508)
Date Mon, 19 Oct 2020 12:11:54 GMT
This is an automated email from the ASF dual-hosted git repository.

vongosling pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a65561  support set log output path (#508)
2a65561 is described below

commit 2a6556176df6c4c7b3bc6cc1c7267660e39c6a0f
Author: Klaus <sunforcherry@gmail.com>
AuthorDate: Mon Oct 19 20:11:47 2020 +0800

    support set log output path (#508)
    
    * support set log output path
    
    * err return definition.
    
    Co-authored-by: John Sun <sunqiang@styd.cn>
---
 rlog/log.go | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/rlog/log.go b/rlog/log.go
index 444ec3f..3e3dfd3 100644
--- a/rlog/log.go
+++ b/rlog/log.go
@@ -42,6 +42,7 @@ type Logger interface {
 	Error(msg string, fields map[string]interface{})
 	Fatal(msg string, fields map[string]interface{})
 	Level(level string)
+	OutputPath(path string) (err error)
 }
 
 func init() {
@@ -102,6 +103,7 @@ func (l *defaultLogger) Fatal(msg string, fields map[string]interface{})
{
 	}
 	l.logger.WithFields(fields).Fatal(msg)
 }
+
 func (l *defaultLogger) Level(level string) {
 	switch strings.ToLower(level) {
 	case "debug":
@@ -115,6 +117,17 @@ func (l *defaultLogger) Level(level string) {
 	}
 }
 
+func (l *defaultLogger) OutputPath(path string) (err error) {
+	var file *os.File
+	file, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
+	if err != nil {
+		return
+	}
+
+	l.logger.Out = file
+	return
+}
+
 // SetLogger use specified logger user customized, in general, we suggest user to replace
the default logger with specified
 func SetLogger(logger Logger) {
 	rLog = logger
@@ -126,6 +139,14 @@ func SetLogLevel(level string) {
 	rLog.Level(level)
 }
 
+func SetOutputPath(path string) (err error) {
+	if "" == path {
+		return
+	}
+
+	return rLog.OutputPath(path)
+}
+
 func Debug(msg string, fields map[string]interface{}) {
 	rLog.Debug(msg, fields)
 }


Mime
View raw message