forked from ConnectAI-E/feishu-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:toeasy/Feishu-OpenAI into toeasy-…
…master
- Loading branch information
Showing
16 changed files
with
170 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package logger | ||
|
||
import ( | ||
"bytes" | ||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
"strings" | ||
) | ||
|
||
var logger = logrus.New() | ||
|
||
func init() { | ||
|
||
logger.SetFormatter(&formatter{}) | ||
|
||
logger.SetReportCaller(true) | ||
|
||
gin.DefaultWriter = logger.Out | ||
|
||
logger.Level = logrus.DebugLevel | ||
|
||
} | ||
|
||
type Fields logrus.Fields | ||
|
||
// Debugf logs a message at level Debug on the standard logger. | ||
func Debugf(format string, args ...interface{}) { | ||
if logger.Level >= logrus.DebugLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Debugf(format, args...) | ||
} | ||
} | ||
|
||
// Warnf logs a message at level Warn on the standard logger. | ||
func Warnf(format string, args ...interface{}) { | ||
if logger.Level >= logrus.WarnLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Warnf(format, args...) | ||
} | ||
} | ||
|
||
// Errorf logs a message at level Error on the standard logger. | ||
func Errorf(format string, args ...interface{}) { | ||
if logger.Level >= logrus.ErrorLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Errorf(format, args...) | ||
} | ||
} | ||
|
||
// Fatalf logs a message at level Fatal on the standard logger. | ||
func Fatalf(format string, args ...interface{}) { | ||
if logger.Level >= logrus.FatalLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Fatalf(format, args...) | ||
} | ||
} | ||
|
||
func Debug(format string, args ...interface{}) { | ||
if logger.Level >= logrus.DebugLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Debug(format, args) | ||
} | ||
} | ||
|
||
// Info logs a message at level Info on the standard logger. | ||
func Info(format string, args ...interface{}) { | ||
if logger.Level >= logrus.InfoLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Info(format, args) | ||
} | ||
} | ||
|
||
// Warn logs a message at level Warn on the standard logger. | ||
func Warn(format string, args ...interface{}) { | ||
if logger.Level >= logrus.WarnLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Warn(format, args) | ||
} | ||
} | ||
|
||
// Error logs a message at level Error on the standard logger. | ||
func Error(format string, args ...interface{}) { | ||
if logger.Level >= logrus.ErrorLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Error(format, args) | ||
} | ||
} | ||
|
||
// Fatal logs a message at level Fatal on the standard logger. | ||
func Fatal(format string, args ...interface{}) { | ||
if logger.Level >= logrus.FatalLevel { | ||
entry := logger.WithFields(logrus.Fields{}) | ||
entry.Fatal(format, args) | ||
} | ||
} | ||
|
||
// Formatter implements logrus.Formatter interface. | ||
type formatter struct { | ||
prefix string | ||
} | ||
|
||
// Format building log message. | ||
func (f *formatter) Format(entry *logrus.Entry) ([]byte, error) { | ||
var sb bytes.Buffer | ||
|
||
sb.WriteString("[" + strings.ToUpper(entry.Level.String()) + "]") | ||
sb.WriteString(entry.Time.Format("2006-01-02 15:04:05")) | ||
sb.WriteString(" ") | ||
//sb.WriteString(" ") | ||
//sb.WriteString(f.prefix) | ||
sb.WriteString(entry.Message) | ||
sb.WriteString("\n") | ||
|
||
return sb.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.