add log
This commit is contained in:
parent
a0826d5361
commit
ebfb2c1ca5
|
@ -3,21 +3,23 @@ package config
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"log"
|
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"git.pyer.club/kingecg/gologger"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config 系统配置结构体
|
// Config 系统配置结构体
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Server ServerConfig `yaml:"server" json:"server"`
|
Server ServerConfig `yaml:"server" json:"server"`
|
||||||
Storage StorageConfig `yaml:"storage" json:"storage"`
|
Storage StorageConfig `yaml:"storage" json:"storage"`
|
||||||
|
Log gologger.LoggersConfig `yaml:"log" json:"log"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfig 服务器配置
|
// ServerConfig 服务器配置
|
||||||
|
@ -49,6 +51,20 @@ func NewDefaultConfig() *Config {
|
||||||
Engine: "memory",
|
Engine: "memory",
|
||||||
DataPath: "/var/lib/goaidb",
|
DataPath: "/var/lib/goaidb",
|
||||||
},
|
},
|
||||||
|
Log: gologger.LoggersConfig{
|
||||||
|
Appenders: map[string]gologger.LogAppenderConfig{
|
||||||
|
"console": {
|
||||||
|
Type: "console",
|
||||||
|
Formatter: "text",
|
||||||
|
Options: map[string]interface{}{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Categories: map[string]gologger.LogConfig{
|
||||||
|
"default": {
|
||||||
|
Appenders: []string{"console"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module github.com/kingecg/goaidb
|
module git.pyer.club/kingecg/goaidb
|
||||||
|
|
||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ go 1.23
|
||||||
// require github.com/mongodb/mongo-go-driver/v2 v2.0.0
|
// require github.com/mongodb/mongo-go-driver/v2 v2.0.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
git.pyer.club/kingecg/gologger v1.0.8 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,3 +1,7 @@
|
||||||
|
git.pyer.club/kingecg/gologger v1.0.7 h1:sMrz+F806Whon6kzxVPYYMqB5frUvvJQEWa2zevRvX8=
|
||||||
|
git.pyer.club/kingecg/gologger v1.0.7/go.mod h1:SNSl2jRHPzIpHSzdKOoVG798rtYMjPDPFyxUrEgivkY=
|
||||||
|
git.pyer.club/kingecg/gologger v1.0.8 h1:DaPDIsn0Jc+hF97+MRuG//W9zuXdPR7VTc+nPkXvym0=
|
||||||
|
git.pyer.club/kingecg/gologger v1.0.8/go.mod h1:SNSl2jRHPzIpHSzdKOoVG798rtYMjPDPFyxUrEgivkY=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
|
|
19
main.go
19
main.go
|
@ -9,9 +9,10 @@ import (
|
||||||
|
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/kingecg/goaidb/config"
|
"git.pyer.club/kingecg/goaidb/config"
|
||||||
"github.com/kingecg/goaidb/network"
|
"git.pyer.club/kingecg/goaidb/log"
|
||||||
"github.com/kingecg/goaidb/storage"
|
"git.pyer.club/kingecg/goaidb/network"
|
||||||
|
"git.pyer.club/kingecg/goaidb/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getExeDir() string {
|
func getExeDir() string {
|
||||||
|
@ -36,7 +37,8 @@ func main() {
|
||||||
// 解析配置文件
|
// 解析配置文件
|
||||||
cfg, err := config.ParseConfig(configPath)
|
cfg, err := config.ParseConfig(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "配置加载失败: %v\n", err)
|
// fmt.Fprintf(os.Stderr, "配置加载失败: %v\n", err)
|
||||||
|
log.Error("配置加载失败", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +49,7 @@ func main() {
|
||||||
err = config.WatchConfig(configPath)
|
err = config.WatchConfig(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "配置监控启动失败: %v\n", err)
|
fmt.Fprintf(os.Stderr, "配置监控启动失败: %v\n", err)
|
||||||
|
log.Error("配置监控启动失败", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +59,7 @@ func main() {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
<-sigChan
|
<-sigChan
|
||||||
fmt.Println("正在关闭...")
|
log.Info("正在关闭...")
|
||||||
config.CloseWatcher()
|
config.CloseWatcher()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
@ -64,7 +67,7 @@ func main() {
|
||||||
// 初始化存储引擎(默认使用内存引擎)
|
// 初始化存储引擎(默认使用内存引擎)
|
||||||
storageEngine, err := storage.NewMemoryEngine()
|
storageEngine, err := storage.NewMemoryEngine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to initialize storage engine: %v\n", err)
|
log.Error("Failed to initialize storage engine: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,10 +77,10 @@ func main() {
|
||||||
// 启动服务
|
// 启动服务
|
||||||
listener, err := net.Listen("tcp", conf.Server.Host+":"+fmt.Sprintf("%d", conf.Server.Port))
|
listener, err := net.Listen("tcp", conf.Server.Host+":"+fmt.Sprintf("%d", conf.Server.Port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to start server: %v\n", err)
|
log.Error("Failed to start server: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("GoAIDB started on port 27017")
|
log.Info("GoAIDB started on port", conf.Server.Port)
|
||||||
server.Serve(listener)
|
server.Serve(listener)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"github.com/kingecg/goaidb/protocol"
|
|
||||||
"github.com/kingecg/goaidb/query"
|
"git.pyer.club/kingecg/goaidb/protocol"
|
||||||
"github.com/kingecg/goaidb/storage"
|
"git.pyer.club/kingecg/goaidb/query"
|
||||||
|
"git.pyer.club/kingecg/goaidb/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server 网络服务器结构体
|
// Server 网络服务器结构体
|
||||||
|
|
|
@ -3,8 +3,9 @@ package query
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/kingecg/goaidb/protocol"
|
|
||||||
"github.com/kingecg/goaidb/storage"
|
"git.pyer.club/kingecg/goaidb/protocol"
|
||||||
|
"git.pyer.club/kingecg/goaidb/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleQuery 处理查询请求
|
// HandleQuery 处理查询请求
|
||||||
|
|
Loading…
Reference in New Issue