Skip to content

Commit 00603f3

Browse files
committed
增加转换日志配置的方法,使用默认Channel
1 parent e8257e9 commit 00603f3

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

cmd/LogBeetle/sub/root.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/reggiepy/LogBeetle/pkg/config"
77
"github.com/reggiepy/LogBeetle/pkg/consumer/logconsumer"
88
"github.com/reggiepy/LogBeetle/pkg/consumer/nsqconsumer"
9+
"github.com/reggiepy/LogBeetle/pkg/convert"
910
"github.com/reggiepy/LogBeetle/pkg/logger"
1011
"github.com/reggiepy/LogBeetle/pkg/producer/nsqproducer"
1112
"github.com/reggiepy/LogBeetle/pkg/worker"
@@ -58,7 +59,8 @@ var rootCmd = cobra.Command{
5859
Version: "",
5960
Run: func(cmd *cobra.Command, args []string) {
6061
_ = config.ShowConfig("simple")
61-
err := logger.InitLogger(config.Instance)
62+
loggerConfig, err := convert.ConfigToLoggerConfig(config.Instance)
63+
err = logger.InitLogger(*loggerConfig)
6264
if err != nil {
6365
fmt.Println(err.Error())
6466
os.Exit(1)
@@ -183,7 +185,6 @@ func serverStart() {
183185
Address: nsqConfig.NSQDAddress,
184186
AuthSecret: nsqConfig.AuthSecret,
185187
Topic: "test",
186-
Channel: "test_channel",
187188
}, "test.log"),
188189
)
189190

@@ -196,7 +197,6 @@ func serverStart() {
196197
Address: nsqConfig.NSQDAddress,
197198
AuthSecret: nsqConfig.AuthSecret,
198199
Topic: consumerConfig.Topic,
199-
Channel: consumerConfig.Channel,
200200
}, consumerConfig.FileName),
201201
)
202202
}

log-beetle.tmp.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ ConsumerConfig:
1414
Consumers:
1515
- Name: "test"
1616
Topic: "test"
17-
Channel: "test"
1817
FileName: "test.log"
1918

2019
NSQConfig:

pkg/config/config.go

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var Instance *Config
1313
type Consumer struct {
1414
Name string `yaml:"Name"`
1515
Topic string `yaml:"Topic"`
16-
Channel string `yaml:"Channel"`
1716
FileName string `yaml:"FileName"`
1817
}
1918

pkg/consumer/nsqconsumer/consumer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
type NsqConsumerConfig struct {
99
Topic string
10-
Channel string
1110
Address string
1211
AuthSecret string
1312
Handler *MessageHandler
@@ -20,7 +19,7 @@ func NewNsqConsumer(config NsqConsumerConfig) *nsq.Consumer {
2019
log.Fatalf("Failed to set auth_secret: %v", err)
2120
}
2221
}
23-
consumer, err := nsq.NewConsumer(config.Topic, config.Channel, cfg)
22+
consumer, err := nsq.NewConsumer(config.Topic, "consumer", cfg)
2423
if err != nil {
2524
log.Fatalf("Failed to create NSQ Consumer: %v", err)
2625
}

pkg/convert/logger.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package convert
2+
3+
import (
4+
"encoding/json"
5+
"github.com/reggiepy/LogBeetle/pkg/config"
6+
"github.com/reggiepy/LogBeetle/pkg/logger"
7+
)
8+
9+
func ConfigToLoggerConfig(config *config.Config) (*logger.Config, error) {
10+
var ret = &logger.Config{}
11+
jsonBytes, _ := json.Marshal(config.LogConfig)
12+
err := json.Unmarshal(jsonBytes, ret)
13+
if err != nil {
14+
return nil, err
15+
}
16+
return ret, nil
17+
}

0 commit comments

Comments
 (0)