Skip to content

Commit

Permalink
功能: 支持设置log level
Browse files Browse the repository at this point in the history
  • Loading branch information
yjs committed Apr 22, 2023
1 parent 37d87e9 commit 4c95ea7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type Logs struct {
Dir string
Level string

//
accessLogFile *os.File
Expand Down Expand Up @@ -57,5 +58,7 @@ func (l *Logs) Setup() (err error) {
}),
})

logger.SetLevel(l.Level)

return nil
}
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func main() {
EnvVars: []string{"LOGS_DIR"},
Value: "/tmp/chatgpt-for-chatbot-feishu",
},
&cli.StringFlag{
Name: "logs-level",
Usage: "The logs level",
EnvVars: []string{"LOGS_LEVEL"},
Value: "INFO",
},
&cli.StringFlag{
Name: "offline-message",
Usage: "The message to use for offline status",
Expand Down Expand Up @@ -145,6 +151,7 @@ func main() {
app.Command(func(ctx *cli.Context) (err error) {
return ServeFeishuBot(&FeishuBotConfig{
LogsDir: ctx.String("logs-dir"),
LogsLevel: ctx.String("logs-level"),
Port: ctx.Int64("port"),
APIPath: ctx.String("api-path"),
OpenAIAPIKey: ctx.String("openai-api-key"),
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type FeishuBotConfig struct {
ConversationLanguage string
//
LogsDir string
LogsLevel string
//
OfflineMessage string
//
Expand Down Expand Up @@ -90,6 +91,7 @@ func ServeFeishuBot(cfg *FeishuBotConfig) (err error) {

logs := &Logs{
Dir: cfg.LogsDir,
Level: cfg.LogsLevel,
}
if err := logs.Setup(); err != nil {
return fmt.Errorf("failed to setup logs: %v", err)
Expand Down

0 comments on commit 4c95ea7

Please sign in to comment.