Skip to content

Commit

Permalink
chore: log
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxsen committed Jul 3, 2024
1 parent e9af054 commit a5decd6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
20 changes: 19 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,30 @@ type SwitchConfig struct {
EnableLinkMode bool `json:"enable_link_mode"`
}

func defaultConfig() *Config {
return &Config{
Plugins: []string{
"javbus",
"javhoo",
"jav321",
"caribpr",
"fc2",
"avsox",
},
Handlers: []string{
"poster_cropper",
"image_transcoder",
"plot_translater",
},
}
}

func Parse(f string) (*Config, error) {
raw, err := os.ReadFile(f)
if err != nil {
return nil, err
}
c := &Config{}
c := defaultConfig()
if err := json.Unmarshal(raw, c); err != nil {
return nil, err
}
Expand Down
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ func main() {
log.Fatalf("parse config failed, err:%v", err)
}
logkit := logger.Init(c.LogConfig.File, c.LogConfig.Level, int(c.LogConfig.FileCount), int(c.LogConfig.FileSize), int(c.LogConfig.KeepDays), c.LogConfig.Console)

logkit.Info("support plugins", zap.Strings("plugins", plugin.Plugins()))
logkit.Info("support handlers", zap.Strings("handlers", handler.Handlers()))
logkit.Info("current use plugins", zap.Strings("plugins", c.Plugins))
logkit.Info("current use handlers", zap.Strings("handlers", c.Handlers))
logkit.Info("use naming rule", zap.String("rule", c.Naming))
logkit.Info("scrape from dir", zap.String("dir", c.ScanDir))
logkit.Info("save to dir", zap.String("dir", c.SaveDir))
logkit.Info("use data dir", zap.String("dir", c.DataDir))
logkit.Info("current switch options", zap.Any("options", c.SwitchConfig))

if err := store.Init(filepath.Join(c.DataDir, "cache")); err != nil {
logkit.Fatal("init store failed", zap.Error(err))
}
Expand All @@ -52,9 +63,12 @@ func main() {
if err != nil {
logkit.Fatal("build capture runner failed", zap.Error(err))
}
logkit.Info("capture kit init succ, start scraping")
if err := cap.Run(context.Background()); err != nil {
logkit.Fatal("run capture logic failed", zap.Error(err))
logkit.Error("run capture kit failed", zap.Error(err))
return
}
logkit.Info("run capture kit finish, all file scrape succ")
}

func buildCapture(c *config.Config, ss []searcher.ISearcher, ps []processor.IProcessor) (*capture.Capture, error) {
Expand Down
9 changes: 9 additions & 0 deletions processor/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"av-capture/model"
"context"
"fmt"
"sort"
)

type IHandler interface {
Expand Down Expand Up @@ -31,3 +32,11 @@ func HandlerToCreator(h IHandler) CreatorFunc {
return h, nil
}
}

func Handlers() []string {
rs := make([]string, 0, len(mp))
for k := range mp {
rs = append(rs, k)
}
return sort.StringSlice(rs)
}
9 changes: 9 additions & 0 deletions searcher/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"fmt"
"net/http"
"sort"
)

type PluginContext struct {
Expand Down Expand Up @@ -125,3 +126,11 @@ func PluginToCreator(plg IPlugin) CreatorFunc {
return plg, nil
}
}

func Plugins() []string {
rs := make([]string, 0, len(mp))
for k := range mp {
rs = append(rs, k)
}
return sort.StringSlice(rs)
}

0 comments on commit a5decd6

Please sign in to comment.