Skip to content

Commit

Permalink
Fix log
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jan 2, 2023
1 parent 68777fd commit 7be7589
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
6 changes: 1 addition & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ var rootCmd = &cobra.Command{
Version: buildVersion(version, commit, date),
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := loadConfig(cmd, args)
if err != nil {
return err
}
initLogger()
return nil
return loadConfig(cmd, args)
},
}

Expand Down
9 changes: 4 additions & 5 deletions leetcode/cache_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/hashicorp/go-hclog"
"github.com/j178/leetgo/config"
"github.com/j178/leetgo/utils"
)

Expand All @@ -20,7 +19,7 @@ type jsonCache struct {
}

func newJsonCache(path string) QuestionsCache {
return &jsonCache{path: config.Get().LeetCodeCacheFile()}
return &jsonCache{path: path}
}

func (c *jsonCache) doLoad() error {
Expand Down Expand Up @@ -52,7 +51,7 @@ func (c *jsonCache) load() {
func() {
err := c.doLoad()
if err != nil {
hclog.L().Warn("failed to load jsonCache, try updating with `leetgo jsonCache update`")
hclog.L().Warn("failed to load cache, try updating with `leetgo cache update`")
return
}
c.checkUpdateTime()
Expand All @@ -66,7 +65,7 @@ func (c *jsonCache) checkUpdateTime() {
return
}
if time.Since(stat.ModTime()) >= 14*24*time.Hour {
hclog.L().Warn("jsonCache is too old, try updating with `leetgo jsonCache update`")
hclog.L().Warn("cache is too old, try updating with `leetgo cache update`")
}
}

Expand Down Expand Up @@ -109,7 +108,7 @@ func (c *jsonCache) Update(client Client) error {
if err != nil {
return err
}
hclog.L().Info("jsonCache updated", "path", c.path)
hclog.L().Info("cache updated", "path", c.path)
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions leetcode/cache_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *sqliteCache) load() {
var err error
c.db, err = sql.Open("sqlite3", c.path)
if err != nil {
hclog.L().Warn("failed to load jsonCache, try updating with `leetgo jsonCache update`")
hclog.L().Warn("failed to load cache, try updating with `leetgo cache update`")
return
}
c.checkUpdateTime()
Expand All @@ -50,7 +50,7 @@ func (c *sqliteCache) checkUpdateTime() {
return
}
if time.Since(time.Unix(ts, 0)) >= 14*24*time.Hour {
hclog.L().Warn("jsonCache is too old, try updating with `leetgo jsonCache update`")
hclog.L().Warn("cache is too old, try updating with `leetgo cache update`")
}
}

Expand Down Expand Up @@ -178,6 +178,6 @@ func (c *sqliteCache) Update(client Client) error {
if err != nil {
return err
}
hclog.L().Info("jsonCache updated", "path", c.path)
hclog.L().Info("cache updated", "path", c.path)
return nil
}

0 comments on commit 7be7589

Please sign in to comment.