diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-02-20 02:25:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-20 02:25:02 +0800 |
commit | 1c09373b4f7dbc68154c817b4ee44bfa3b3f637c (patch) | |
tree | aeec9a80d10f9ef28f0d0b128f8a84bf3cb5bdb1 /internal/db | |
parent | 422a20648466f270de195dce3bca04e977bacd13 (diff) |
log: migrate to unknwon.dev/clog/v2 (#5927)
* Add unknwon.dev/clog/v2
* Update all places
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/access.go | 4 | ||||
-rw-r--r-- | internal/db/action.go | 10 | ||||
-rw-r--r-- | internal/db/admin.go | 4 | ||||
-rw-r--r-- | internal/db/comment.go | 20 | ||||
-rw-r--r-- | internal/db/issue.go | 26 | ||||
-rw-r--r-- | internal/db/issue_mail.go | 4 | ||||
-rw-r--r-- | internal/db/login_source.go | 12 | ||||
-rw-r--r-- | internal/db/migrations/migrations.go | 4 | ||||
-rw-r--r-- | internal/db/migrations/v15.go | 2 | ||||
-rw-r--r-- | internal/db/migrations/v16.go | 2 | ||||
-rw-r--r-- | internal/db/milestone.go | 6 | ||||
-rw-r--r-- | internal/db/mirror.go | 60 | ||||
-rw-r--r-- | internal/db/models.go | 8 | ||||
-rw-r--r-- | internal/db/pull.go | 48 | ||||
-rw-r--r-- | internal/db/release.go | 4 | ||||
-rw-r--r-- | internal/db/repo.go | 64 | ||||
-rw-r--r-- | internal/db/repo_collaboration.go | 4 | ||||
-rw-r--r-- | internal/db/ssh_key.go | 4 | ||||
-rw-r--r-- | internal/db/ssh_key_test.go | 2 | ||||
-rw-r--r-- | internal/db/two_factor.go | 4 | ||||
-rw-r--r-- | internal/db/update.go | 2 | ||||
-rw-r--r-- | internal/db/user.go | 10 | ||||
-rw-r--r-- | internal/db/webhook.go | 24 |
23 files changed, 164 insertions, 164 deletions
diff --git a/internal/db/access.go b/internal/db/access.go index e9c8b5b7..b5c6cd28 100644 --- a/internal/db/access.go +++ b/internal/db/access.go @@ -7,7 +7,7 @@ package db import ( "fmt" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "gogs.io/gogs/internal/db/errors" ) @@ -111,7 +111,7 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) { repo, err := GetRepositoryByID(access.RepoID) if err != nil { if errors.IsRepoNotExist(err) { - log.Error(2, "GetRepositoryByID: %v", err) + log.Error("GetRepositoryByID: %v", err) continue } return nil, err diff --git a/internal/db/action.go b/internal/db/action.go index e3296c70..e177f250 100644 --- a/internal/db/action.go +++ b/internal/db/action.go @@ -13,7 +13,7 @@ import ( "github.com/json-iterator/go" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "github.com/gogs/git-module" @@ -160,7 +160,7 @@ func (a *Action) GetIssueTitle() string { index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { - log.Error(4, "GetIssueByIndex: %v", err) + log.Error("GetIssueByIndex: %v", err) return "500 when get issue" } return issue.Title @@ -170,7 +170,7 @@ func (a *Action) GetIssueContent() string { index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { - log.Error(4, "GetIssueByIndex: %v", err) + log.Error("GetIssueByIndex: %v", err) return "500 when get issue" } return issue.Content @@ -305,7 +305,7 @@ func (push *PushCommits) AvatarLink(email string) string { if err != nil { push.avatars[email] = tool.AvatarLink(email) if !errors.IsUserNotExist(err) { - log.Error(4, "GetUserByEmail: %v", err) + log.Error("GetUserByEmail: %v", err) } } else { push.avatars[email] = u.RelAvatarLink() @@ -490,7 +490,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { // Only update issues via commits when internal issue tracker is enabled if repo.EnableIssues && !repo.EnableExternalTracker { if err = UpdateIssuesCommit(pusher, repo, opts.Commits.Commits); err != nil { - log.Error(2, "UpdateIssuesCommit: %v", err) + log.Error("UpdateIssuesCommit: %v", err) } } } diff --git a/internal/db/admin.go b/internal/db/admin.go index 1fe13002..22f9e1e6 100644 --- a/internal/db/admin.go +++ b/internal/db/admin.go @@ -11,7 +11,7 @@ import ( "time" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "gogs.io/gogs/internal/tool" @@ -75,7 +75,7 @@ func RemoveAllWithNotice(title, path string) { desc := fmt.Sprintf("%s [%s]: %v", title, path, err) log.Warn(desc) if err = CreateRepositoryNotice(desc); err != nil { - log.Error(2, "CreateRepositoryNotice: %v", err) + log.Error("CreateRepositoryNotice: %v", err) } } } diff --git a/internal/db/comment.go b/internal/db/comment.go index b2f19508..d0270302 100644 --- a/internal/db/comment.go +++ b/internal/db/comment.go @@ -10,7 +10,7 @@ import ( "time" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" api "github.com/gogs/go-gogs-client" @@ -180,7 +180,7 @@ func (cmt *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) issue.Content = fmt.Sprintf("Reopened #%d", issue.Index) } if err = mailIssueCommentToParticipants(issue, cmt.Poster, mentions); err != nil { - log.Error(2, "mailIssueCommentToParticipants: %v", err) + log.Error("mailIssueCommentToParticipants: %v", err) } return nil @@ -282,10 +282,10 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err // Notify watchers for whatever action comes in, ignore if no action type. if act.OpType > 0 { if err = notifyWatchers(e, act); err != nil { - log.Error(2, "notifyWatchers: %v", err) + log.Error("notifyWatchers: %v", err) } if err = comment.mailParticipants(e, act.OpType, opts.Issue); err != nil { - log.Error(2, "MailParticipants: %v", err) + log.Error("MailParticipants: %v", err) } } @@ -356,7 +356,7 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri Repository: repo.APIFormat(nil), Sender: doer.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) + log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) } return comment, nil @@ -465,7 +465,7 @@ func UpdateComment(doer *User, c *Comment, oldContent string) (err error) { } if err = c.Issue.LoadAttributes(); err != nil { - log.Error(2, "Issue.LoadAttributes [issue_id: %d]: %v", c.IssueID, err) + log.Error("Issue.LoadAttributes [issue_id: %d]: %v", c.IssueID, err) } else if err = PrepareWebhooks(c.Issue.Repo, HOOK_EVENT_ISSUE_COMMENT, &api.IssueCommentPayload{ Action: api.HOOK_ISSUE_COMMENT_EDITED, Issue: c.Issue.APIFormat(), @@ -478,7 +478,7 @@ func UpdateComment(doer *User, c *Comment, oldContent string) (err error) { Repository: c.Issue.Repo.APIFormat(nil), Sender: doer.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", c.ID, err) + log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err) } return nil @@ -516,11 +516,11 @@ func DeleteCommentByID(doer *User, id int64) error { _, err = DeleteAttachmentsByComment(comment.ID, true) if err != nil { - log.Error(2, "Failed to delete attachments by comment[%d]: %v", comment.ID, err) + log.Error("Failed to delete attachments by comment[%d]: %v", comment.ID, err) } if err = comment.Issue.LoadAttributes(); err != nil { - log.Error(2, "Issue.LoadAttributes [issue_id: %d]: %v", comment.IssueID, err) + log.Error("Issue.LoadAttributes [issue_id: %d]: %v", comment.IssueID, err) } else if err = PrepareWebhooks(comment.Issue.Repo, HOOK_EVENT_ISSUE_COMMENT, &api.IssueCommentPayload{ Action: api.HOOK_ISSUE_COMMENT_DELETED, Issue: comment.Issue.APIFormat(), @@ -528,7 +528,7 @@ func DeleteCommentByID(doer *User, id int64) error { Repository: comment.Issue.Repo.APIFormat(nil), Sender: doer.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) + log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) } return nil } diff --git a/internal/db/issue.go b/internal/db/issue.go index f176f876..a35e2d89 100644 --- a/internal/db/issue.go +++ b/internal/db/issue.go @@ -10,7 +10,7 @@ import ( "time" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" api "github.com/gogs/go-gogs-client" @@ -231,7 +231,7 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) { if issue.IsPull { err = issue.PullRequest.LoadIssue() if err != nil { - log.Error(2, "LoadIssue: %v", err) + log.Error("LoadIssue: %v", err) return } err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ @@ -251,7 +251,7 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) { }) } if err != nil { - log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) + log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } } @@ -346,7 +346,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) { if issue.IsPull { err = issue.PullRequest.LoadIssue() if err != nil { - log.Error(2, "LoadIssue: %v", err) + log.Error("LoadIssue: %v", err) return } err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ @@ -366,7 +366,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) { }) } if err != nil { - log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) + log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } return nil @@ -503,7 +503,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e err = PrepareWebhooks(repo, HOOK_EVENT_ISSUES, apiIssues) } if err != nil { - log.Error(2, "PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err) + log.Error("PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err) } return nil @@ -545,7 +545,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) { }) } if err != nil { - log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) + log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } return nil @@ -587,7 +587,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) { }) } if err != nil { - log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) + log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } return nil @@ -601,7 +601,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) { issue.Assignee, err = GetUserByID(issue.AssigneeID) if err != nil && !errors.IsUserNotExist(err) { - log.Error(4, "GetUserByID [assignee_id: %v]: %v", issue.AssigneeID, err) + log.Error("GetUserByID [assignee_id: %v]: %v", issue.AssigneeID, err) return nil } @@ -636,7 +636,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) { err = PrepareWebhooks(issue.Repo, HOOK_EVENT_ISSUES, apiIssues) } if err != nil { - log.Error(4, "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, isRemoveAssignee, err) + log.Error("PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, isRemoveAssignee, err) } return nil @@ -777,10 +777,10 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) RepoName: repo.Name, IsPrivate: repo.IsPrivate, }); err != nil { - log.Error(2, "NotifyWatchers: %v", err) + log.Error("NotifyWatchers: %v", err) } if err = issue.MailParticipants(); err != nil { - log.Error(2, "MailParticipants: %v", err) + log.Error("MailParticipants: %v", err) } if err = PrepareWebhooks(repo, HOOK_EVENT_ISSUES, &api.IssuesPayload{ @@ -790,7 +790,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) Repository: repo.APIFormat(nil), Sender: issue.Poster.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks: %v", err) + log.Error("PrepareWebhooks: %v", err) } return nil diff --git a/internal/db/issue_mail.go b/internal/db/issue_mail.go index b1f81cc8..31643f3a 100644 --- a/internal/db/issue_mail.go +++ b/internal/db/issue_mail.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "gogs.io/gogs/internal/mailer" "gogs.io/gogs/internal/markup" @@ -173,7 +173,7 @@ func (issue *Issue) MailParticipants() (err error) { } if err = mailIssueCommentToParticipants(issue, issue.Poster, mentions); err != nil { - log.Error(2, "mailIssueCommentToParticipants: %v", err) + log.Error("mailIssueCommentToParticipants: %v", err) } return nil diff --git a/internal/db/login_source.go b/internal/db/login_source.go index c9e5dcc9..383e8b46 100644 --- a/internal/db/login_source.go +++ b/internal/db/login_source.go @@ -19,8 +19,8 @@ import ( "github.com/go-macaron/binding" "github.com/json-iterator/go" "github.com/unknwon/com" - log "gopkg.in/clog.v1" "gopkg.in/ini.v1" + log "unknwon.dev/clog/v2" "xorm.io/core" "xorm.io/xorm" @@ -469,7 +469,7 @@ func LoadAuthSources() { paths, err := com.GetFileListBySuffix(authdPath, ".conf") if err != nil { - log.Fatal(2, "Failed to list authentication sources: %v", err) + log.Fatal("Failed to list authentication sources: %v", err) } localLoginSources.sources = make([]*LoginSource, 0, len(paths)) @@ -477,7 +477,7 @@ func LoadAuthSources() { for _, fpath := range paths { authSource, err := ini.Load(fpath) if err != nil { - log.Fatal(2, "Failed to load authentication source: %v", err) + log.Fatal("Failed to load authentication source: %v", err) } authSource.NameMapper = ini.TitleUnderscore @@ -496,7 +496,7 @@ func LoadAuthSources() { fi, err := os.Stat(fpath) if err != nil { - log.Fatal(2, "Failed to load authentication source: %v", err) + log.Fatal("Failed to load authentication source: %v", err) } loginSource.Updated = fi.ModTime() @@ -519,11 +519,11 @@ func LoadAuthSources() { loginSource.Type = LOGIN_GITHUB loginSource.Cfg = &GitHubConfig{} default: - log.Fatal(2, "Failed to load authentication source: unknown type '%s'", authType) + log.Fatal("Failed to load authentication source: unknown type '%s'", authType) } if err = authSource.Section("config").MapTo(loginSource.Cfg); err != nil { - log.Fatal(2, "Failed to parse authentication source 'config': %v", err) + log.Fatal("Failed to parse authentication source 'config': %v", err) } localLoginSources.sources = append(localLoginSources.sources, loginSource) diff --git a/internal/db/migrations/migrations.go b/internal/db/migrations/migrations.go index 79534484..a4f47441 100644 --- a/internal/db/migrations/migrations.go +++ b/internal/db/migrations/migrations.go @@ -10,7 +10,7 @@ import ( "time" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "gogs.io/gogs/internal/tool" @@ -93,7 +93,7 @@ func Migrate(x *xorm.Engine) error { v := currentVersion.Version if _MIN_DB_VER > v { - log.Fatal(0, ` + log.Fatal(` Hi there, thank you for using Gogs for so long! However, Gogs has stopped supporting auto-migration from your previously installed version. But the good news is, it's very easy to fix this problem! diff --git a/internal/db/migrations/v15.go b/internal/db/migrations/v15.go index d9c913df..0ef77555 100644 --- a/internal/db/migrations/v15.go +++ b/internal/db/migrations/v15.go @@ -12,7 +12,7 @@ import ( "strings" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "gogs.io/gogs/internal/osutil" diff --git a/internal/db/migrations/v16.go b/internal/db/migrations/v16.go index b374be39..b2eb813b 100644 --- a/internal/db/migrations/v16.go +++ b/internal/db/migrations/v16.go @@ -9,8 +9,8 @@ import ( "path/filepath" "strings" + log "unknwon.dev/clog/v2" "xorm.io/xorm" - log "gopkg.in/clog.v1" "github.com/gogs/git-module" diff --git a/internal/db/milestone.go b/internal/db/milestone.go index 10c5c556..507c0e89 100644 --- a/internal/db/milestone.go +++ b/internal/db/milestone.go @@ -8,7 +8,7 @@ import ( "fmt" "time" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" api "github.com/gogs/go-gogs-client" @@ -336,7 +336,7 @@ func ChangeMilestoneAssign(doer *User, issue *Issue, oldMilestoneID int64) (err if issue.IsPull { err = issue.PullRequest.LoadIssue() if err != nil { - log.Error(2, "LoadIssue: %v", err) + log.Error("LoadIssue: %v", err) return } err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ @@ -356,7 +356,7 @@ func ChangeMilestoneAssign(doer *User, issue *Issue, oldMilestoneID int64) (err }) } if err != nil { - log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) + log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } return nil diff --git a/internal/db/mirror.go b/internal/db/mirror.go index 0481e1d0..33c837fb 100644 --- a/internal/db/mirror.go +++ b/internal/db/mirror.go @@ -12,8 +12,8 @@ import ( "time" "github.com/unknwon/com" - log "gopkg.in/clog.v1" "gopkg.in/ini.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "github.com/gogs/git-module" @@ -58,7 +58,7 @@ func (m *Mirror) AfterSet(colName string, _ xorm.Cell) { case "repo_id": m.Repo, err = GetRepositoryByID(m.RepoID) if err != nil { - log.Error(3, "GetRepositoryByID [%d]: %v", m.ID, err) + log.Error("GetRepositoryByID [%d]: %v", m.ID, err) } case "updated_unix": m.LastSync = time.Unix(m.LastSyncUnix, 0).Local() @@ -119,7 +119,7 @@ func (m *Mirror) readAddress() { cfg, err := ini.Load(m.Repo.GitConfigPath()) if err != nil { - log.Error(2, "Load: %v", err) + log.Error("Load: %v", err) return } m.address = cfg.Section("remote \"origin\"").Key("url").Value() @@ -233,12 +233,12 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult { case strings.HasPrefix(lines[i], " "): // New commits of a reference delimIdx := strings.Index(lines[i][3:], " ") if delimIdx == -1 { - log.Error(2, "SHA delimiter not found: %q", lines[i]) + log.Error("SHA delimiter not found: %q", lines[i]) continue } shas := strings.Split(lines[i][3:delimIdx+3], "..") if len(shas) != 2 { - log.Error(2, "Expect two SHAs but not what found: %q", lines[i]) + log.Error("Expect two SHAs but not what found: %q", lines[i]) continue } results = append(results, &mirrorSyncResult{ @@ -268,7 +268,7 @@ func (m *Mirror) runSync() ([]*mirrorSyncResult, bool) { }) { desc := fmt.Sprintf("Source URL of mirror repository '%s' is not accessible: %s", m.Repo.FullName(), m.MosaicsAddress()) if err := CreateRepositoryNotice(desc); err != nil { - log.Error(2, "CreateRepositoryNotice: %v", err) + log.Error("CreateRepositoryNotice: %v", err) } return nil, false } @@ -281,17 +281,17 @@ func (m *Mirror) runSync() ([]*mirrorSyncResult, bool) { timeout, repoPath, fmt.Sprintf("Mirror.runSync: %s", repoPath), "git", gitArgs...) if err != nil { - desc := fmt.Sprintf("Fail to update mirror repository '%s': %s", repoPath, stderr) - log.Error(2, desc) + desc := fmt.Sprintf("Failed to update mirror repository '%s': %s", repoPath, stderr) + log.Error(desc) if err = CreateRepositoryNotice(desc); err != nil { - log.Error(2, "CreateRepositoryNotice: %v", err) + log.Error("CreateRepositoryNotice: %v", err) } return nil, false } output := stderr if err := m.Repo.UpdateSize(); err != nil { - log.Error(2, "UpdateSize [repo_id: %d]: %v", m.Repo.ID, err) + log.Error("UpdateSize [repo_id: %d]: %v", m.Repo.ID, err) } if m.Repo.HasWiki() { @@ -299,10 +299,10 @@ func (m *Mirror) runSync() ([]*mirrorSyncResult, bool) { if _, stderr, err := process.ExecDir( timeout, wikiPath, fmt.Sprintf("Mirror.runSync: %s", wikiPath), "git", "remote", "update", "--prune"); err != nil { - desc := fmt.Sprintf("Fail to update mirror wiki repository '%s': %s", wikiPath, stderr) - log.Error(2, desc) + desc := fmt.Sprintf("Failed to update mirror wiki repository '%s': %s", wikiPath, stderr) + log.Error(desc) if err = CreateRepositoryNotice(desc); err != nil { - log.Error(2, "CreateRepositoryNotice: %v", err) + log.Error("CreateRepositoryNotice: %v", err) } } } @@ -353,14 +353,14 @@ func MirrorUpdate() { if err := x.Where("next_update_unix<=?", time.Now().Unix()).Iterate(new(Mirror), func(idx int, bean interface{}) error { m := bean.(*Mirror) if m.Repo == nil { - log.Error(2, "Disconnected mirror repository found: %d", m.ID) + log.Error("Disconnected mirror repository found: %d", m.ID) return nil } MirrorQueue.Add(m.RepoID) return nil }); err != nil { - log.Error(2, "MirrorUpdate: %v", err) + log.Error("MirrorUpdate: %v", err) } } @@ -374,7 +374,7 @@ func SyncMirrors() { m, err := GetMirrorByRepoID(com.StrTo(repoID).MustInt64()) if err != nil { - log.Error(2, "GetMirrorByRepoID [%d]: %v", m.RepoID, err) + log.Error("GetMirrorByRepoID [%d]: %v", m.RepoID, err) continue } @@ -385,7 +385,7 @@ func SyncMirrors() { m.ScheduleNextSync() if err = UpdateMirror(m); err != nil { - log.Error(2, "UpdateMirror [%d]: %v", m.RepoID, err) + log.Error("UpdateMirror [%d]: %v", m.RepoID, err) continue } @@ -399,7 +399,7 @@ func SyncMirrors() { } else { gitRepo, err = git.OpenRepository(m.Repo.RepoPath()) if err != nil { - log.Error(2, "OpenRepository [%d]: %v", m.RepoID, err) + log.Error("OpenRepository [%d]: %v", m.RepoID, err) continue } } @@ -413,7 +413,7 @@ func SyncMirrors() { // Delete reference if result.newCommitID == GIT_SHORT_EMPTY_SHA { if err = MirrorSyncDeleteAction(m.Repo, result.refName); err != nil { - log.Error(2, "MirrorSyncDeleteAction [repo_id: %d]: %v", m.RepoID, err) + log.Error("MirrorSyncDeleteAction [repo_id: %d]: %v", m.RepoID, err) } continue } @@ -422,7 +422,7 @@ func SyncMirrors() { isNewRef := false if result.oldCommitID == GIT_SHORT_EMPTY_SHA { if err = MirrorSyncCreateAction(m.Repo, result.refName); err != nil { - log.Error(2, "MirrorSyncCreateAction [repo_id: %d]: %v", m.RepoID, err) + log.Error("MirrorSyncCreateAction [repo_id: %d]: %v", m.RepoID, err) continue } isNewRef = true @@ -435,33 +435,33 @@ func SyncMirrors() { if !isNewRef { oldCommitID, err = git.GetFullCommitID(gitRepo.Path, result.oldCommitID) if err != nil { - log.Error(2, "GetFullCommitID [%d]: %v", m.RepoID, err) + log.Error("GetFullCommitID [%d]: %v", m.RepoID, err) continue } newCommitID, err = git.GetFullCommitID(gitRepo.Path, result.newCommitID) if err != nil { - log.Error(2, "GetFullCommitID [%d]: %v", m.RepoID, err) + log.Error("GetFullCommitID [%d]: %v", m.RepoID, err) continue } commits, err = gitRepo.CommitsBetweenIDs(newCommitID, oldCommitID) if err != nil { - log.Error(2, "CommitsBetweenIDs [repo_id: %d, new_commit_id: %s, old_commit_id: %s]: %v", m.RepoID, newCommitID, oldCommitID, err) + log.Error("CommitsBetweenIDs [repo_id: %d, new_commit_id: %s, old_commit_id: %s]: %v", m.RepoID, newCommitID, oldCommitID, err) continue } } else { refNewCommitID, err := gitRepo.GetBranchCommitID(result.refName) if err != nil { - log.Error(2, "GetFullCommitID [%d]: %v", m.RepoID, err) + log.Error("GetFullCommitID [%d]: %v", m.RepoID, err) continue } if newCommit, err := gitRepo.GetCommit(refNewCommitID); err != nil { - log.Error(2, "GetCommit [repo_id: %d, commit_id: %s]: %v", m.RepoID, refNewCommitID, err) + log.Error("GetCommit [repo_id: %d, commit_id: %s]: %v", m.RepoID, refNewCommitID, err) continue } else { // TODO: Get the commits for the new ref until the closest ancestor branch like Github does commits, err = newCommit.CommitsBeforeLimit(10) if err != nil { - log.Error(2, "CommitsBeforeLimit [repo_id: %d, commit_id: %s]: %v", m.RepoID, refNewCommitID, err) + log.Error("CommitsBeforeLimit [repo_id: %d, commit_id: %s]: %v", m.RepoID, refNewCommitID, err) } oldCommitID = git.EMPTY_SHA newCommitID = refNewCommitID @@ -473,13 +473,13 @@ func SyncMirrors() { NewCommitID: newCommitID, Commits: ListToPushCommits(commits), }); err != nil { - log.Error(2, "MirrorSyncPushAction [repo_id: %d]: %v", m.RepoID, err) + log.Error("MirrorSyncPushAction [repo_id: %d]: %v", m.RepoID, err) continue } } if _, err = x.Exec("UPDATE mirror SET updated_unix = ? WHERE repo_id = ?", time.Now().Unix(), m.RepoID); err != nil { - log.Error(2, "Update 'mirror.updated_unix' [%d]: %v", m.RepoID, err) + log.Error("Update 'mirror.updated_unix' [%d]: %v", m.RepoID, err) continue } @@ -487,14 +487,14 @@ func SyncMirrors() { // update if latest commit date is newer. commitDate, err := git.GetLatestCommitDate(m.Repo.RepoPath(), "") if err != nil { - log.Error(2, "GetLatestCommitDate [%d]: %v", m.RepoID, err) + log.Error("GetLatestCommitDate [%d]: %v", m.RepoID, err) continue } else if commitDate.Before(m.Repo.Updated) { continue } if _, err = x.Exec("UPDATE repository SET updated_unix = ? WHERE id = ?", commitDate.Unix(), m.RepoID); err != nil { - log.Error(2, "Update 'repository.updated_unix' [%d]: %v", m.RepoID, err) + log.Error("Update 'repository.updated_unix' [%d]: %v", m.RepoID, err) continue } } diff --git a/internal/db/models.go b/internal/db/models.go index 75aeaf3a..403c04ff 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -20,7 +20,7 @@ import ( "github.com/json-iterator/go" _ "github.com/lib/pq" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/core" "xorm.io/xorm" @@ -370,20 +370,20 @@ func ImportDatabase(dirPath string, verbose bool) (err error) { meta := make(map[string]interface{}) if err = jsoniter.Unmarshal(scanner.Bytes(), &meta); err != nil { - log.Error(2, "Failed to unmarshal to map: %v", err) + log.Error("Failed to unmarshal to map: %v", err) } // Reset created_unix back to the date save in archive because Insert method updates its value if isInsertProcessor && !skipInsertProcessors[rawTableName] { if _, err = x.Exec("UPDATE "+rawTableName+" SET created_unix=? WHERE id=?", meta["CreatedUnix"], meta["ID"]); err != nil { - log.Error(2, "Failed to reset 'created_unix': %v", err) + log.Error("Failed to reset 'created_unix': %v", err) } } switch rawTableName { case "milestone": if _, err = x.Exec("UPDATE "+rawTableName+" SET deadline_unix=?, closed_date_unix=? WHERE id=?", meta["DeadlineUnix"], meta["ClosedDateUnix"], meta["ID"]); err != nil { - log.Error(2, "Failed to reset 'milestone.deadline_unix', 'milestone.closed_date_unix': %v", err) + log.Error("Failed to reset 'milestone.deadline_unix', 'milestone.closed_date_unix': %v", err) } } } diff --git a/internal/db/pull.go b/internal/db/pull.go index ccc46231..268927eb 100644 --- a/internal/db/pull.go +++ b/internal/db/pull.go @@ -12,7 +12,7 @@ import ( "time" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "github.com/gogs/git-module" @@ -331,12 +331,12 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle } if err = MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil { - log.Error(2, "MergePullRequestAction [%d]: %v", pr.ID, err) + log.Error("MergePullRequestAction [%d]: %v", pr.ID, err) } // Reload pull request information. if err = pr.LoadAttributes(); err != nil { - log.Error(2, "LoadAttributes: %v", err) + log.Error("LoadAttributes: %v", err) return nil } if err = PrepareWebhooks(pr.Issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ @@ -346,13 +346,13 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle Repository: pr.Issue.Repo.APIFormat(nil), Sender: doer.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks: %v", err) + log.Error("PrepareWebhooks: %v", err) return nil } l, err := headGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase) if err != nil { - log.Error(2, "CommitsBetweenIDs: %v", err) + log.Error("CommitsBetweenIDs: %v", err) return nil } @@ -361,7 +361,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle // to avoid strange diff commits produced. mergeCommit, err := baseGitRepo.GetBranchCommit(pr.BaseBranch) if err != nil { - log.Error(2, "GetBranchCommit: %v", err) + log.Error("GetBranchCommit: %v", err) return nil } if mergeStyle == MERGE_STYLE_REGULAR { @@ -370,7 +370,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle commits, err := ListToPushCommits(l).ToApiPayloadCommits(pr.BaseRepo.RepoPath(), pr.BaseRepo.HTMLURL()) if err != nil { - log.Error(2, "ToApiPayloadCommits: %v", err) + log.Error("ToApiPayloadCommits: %v", err) return nil } @@ -385,7 +385,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle Sender: doer.APIFormat(), } if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil { - log.Error(2, "PrepareWebhooks: %v", err) + log.Error("PrepareWebhooks: %v", err) return nil } return nil @@ -490,10 +490,10 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str RepoName: repo.Name, IsPrivate: repo.IsPrivate, }); err != nil { - log.Error(2, "NotifyWatchers: %v", err) + log.Error("NotifyWatchers: %v", err) } if err = pull.MailParticipants(); err != nil { - log.Error(2, "MailParticipants: %v", err) + log.Error("MailParticipants: %v", err) } pr.Issue = pull @@ -505,7 +505,7 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str Repository: repo.APIFormat(nil), Sender: pull.Poster.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks: %v", err) + log.Error("PrepareWebhooks: %v", err) } return nil @@ -667,7 +667,7 @@ func (pr *PullRequest) AddToTaskQueue() { go PullRequestQueue.AddFunc(pr.ID, func() { pr.Status = PULL_REQUEST_STATUS_CHECKING if err := pr.UpdateCols("status"); err != nil { - log.Error(3, "AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err) + log.Error("AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err) } }) } @@ -717,10 +717,10 @@ func addHeadRepoTasks(prs []*PullRequest) { for _, pr := range prs { log.Trace("addHeadRepoTasks[%d]: composing new test task", pr.ID) if err := pr.UpdatePatch(); err != nil { - log.Error(4, "UpdatePatch: %v", err) + log.Error("UpdatePatch: %v", err) continue } else if err := pr.PushToBaseRepo(); err != nil { - log.Error(4, "PushToBaseRepo: %v", err) + log.Error("PushToBaseRepo: %v", err) continue } @@ -734,20 +734,20 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch) prs, err := GetUnmergedPullRequestsByHeadInfo(repoID, branch) if err != nil { - log.Error(2, "Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err) + log.Error("Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err) return } if isSync { if err = PullRequestList(prs).LoadAttributes(); err != nil { - log.Error(2, "PullRequestList.LoadAttributes: %v", err) + log.Error("PullRequestList.LoadAttributes: %v", err) } if err == nil { for _, pr := range prs { pr.Issue.PullRequest = pr if err = pr.Issue.LoadAttributes(); err != nil { - log.Error(2, "LoadAttributes: %v", err) + log.Error("LoadAttributes: %v", err) continue } if err = PrepareWebhooks(pr.Issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ @@ -757,7 +757,7 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool Repository: pr.Issue.Repo.APIFormat(nil), Sender: doer.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks [pull_id: %v]: %v", pr.ID, err) + log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err) continue } } @@ -769,7 +769,7 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool log.Trace("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests", repoID, branch) prs, err = GetUnmergedPullRequestsByBaseInfo(repoID, branch) if err != nil { - log.Error(2, "Find pull requests [base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err) + log.Error("Find pull requests [base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err) return } for _, pr := range prs { @@ -796,7 +796,7 @@ func (pr *PullRequest) checkAndUpdateStatus() { // Make sure there is no waiting test to process before levaing the checking status. if !PullRequestQueue.Exist(pr.ID) { if err := pr.UpdateCols("status"); err != nil { - log.Error(4, "Update[%d]: %v", pr.ID, err) + log.Error("Update[%d]: %v", pr.ID, err) } } } @@ -812,12 +812,12 @@ func TestPullRequests() { pr := bean.(*PullRequest) if err := pr.LoadAttributes(); err != nil { - log.Error(3, "LoadAttributes: %v", err) + log.Error("LoadAttributes: %v", err) return nil } if err := pr.testPatch(); err != nil { - log.Error(3, "testPatch: %v", err) + log.Error("testPatch: %v", err) return nil } prs = append(prs, pr) @@ -836,10 +836,10 @@ func TestPullRequests() { pr, err := GetPullRequestByID(com.StrTo(prID).MustInt64()) if err != nil { - log.Error(4, "GetPullRequestByID[%s]: %v", prID, err) + log.Error("GetPullRequestByID[%s]: %v", prID, err) continue } else if err = pr.testPatch(); err != nil { - log.Error(4, "testPatch[%d]: %v", pr.ID, err) + log.Error("testPatch[%d]: %v", pr.ID, err) continue } diff --git a/internal/db/release.go b/internal/db/release.go index 7712a0af..d0c4fbe6 100644 --- a/internal/db/release.go +++ b/internal/db/release.go @@ -10,7 +10,7 @@ import ( "strings" "time" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "github.com/gogs/git-module" @@ -156,7 +156,7 @@ func (r *Release) preparePublishWebhooks() { Repository: r.Repo.APIFormat(nil), Sender: r.Publisher.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks: %v", err) + log.Error("PrepareWebhooks: %v", err) } } diff --git a/internal/db/repo.go b/internal/db/repo.go index b73e302a..7c6d9e36 100644 --- a/internal/db/repo.go +++ b/internal/db/repo.go @@ -23,8 +23,8 @@ import ( "github.com/nfnt/resize" "github.com/unknwon/cae/zip" "github.com/unknwon/com" - log "gopkg.in/clog.v1" "gopkg.in/ini.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "github.com/gogs/git-module" @@ -59,13 +59,13 @@ func LoadRepoConfig() { for i, t := range types { files, err := conf.AssetDir("conf/" + t) if err != nil { - log.Fatal(4, "Fail to get %s files: %v", t, err) + log.Fatal("Failed to get %s files: %v", t, err) } customPath := path.Join(setting.CustomPath, "conf", t) if com.IsDir(customPath) { customFiles, err := com.StatDir(customPath) if err != nil { - log.Fatal(4, "Fail to get custom %s files: %v", t, err) + log.Fatal("Failed to get custom %s files: %v", t, err) } for _, f := range customFiles { @@ -106,19 +106,19 @@ func NewRepoContext() { // Check Git installation. if _, err := exec.LookPath("git"); err != nil { - log.Fatal(2, "Failed to test 'git' command: %v (forgotten install?)", err) + log.Fatal("Failed to test 'git' command: %v (forgotten install?)", err) } // Check Git version. var err error setting.Git.Version, err = git.BinVersion() if err != nil { - log.Fatal(2, "Failed to get Git version: %v", err) + log.Fatal("Failed to get Git version: %v", err) } log.Trace("Git version: %s", setting.Git.Version) if version.Compare("1.8.3", setting.Git.Version, ">") { - log.Fatal(2, "Gogs requires Git version greater or equal to 1.8.3") + log.Fatal("Gogs requires Git version greater or equal to 1.8.3") } git.HookDir = "custom_hooks" git.HookSampleDir = "hooks" @@ -130,11 +130,11 @@ func NewRepoContext() { // ExitError indicates this config is not set if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" { if _, stderr, gerr := process.Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil { - log.Fatal(4, "Fail to set git %s(%s): %s", configKey, gerr, stderr) + log.Fatal("Failed to set git %s(%s): %s", configKey, gerr, stderr) } log.Info("Git config %s set to %s", configKey, defaultValue) } else { - log.Fatal(4, "Fail to get git %s(%s): %s", configKey, err, stderr) + log.Fatal("Failed to get git %s(%s): %s", configKey, err, stderr) } } } @@ -142,7 +142,7 @@ func NewRepoContext() { // Set git some configurations. if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)", "git", "config", "--global", "core.quotepath", "false"); err != nil { - log.Fatal(2, "Fail to execute 'git config --global core.quotepath false': %v - %s", err, stderr) + log.Fatal("Failed to execute 'git config --global core.quotepath false': %v - %s", err, stderr) } RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp")) @@ -783,7 +783,7 @@ func MigrateRepository(doer, owner *User, opts MigrateRepoOptions) (*Repository, Quiet: true, Timeout: migrateTimeout, }); err != nil { - log.Trace("Fail to clone wiki: %v", err) + log.Trace("Failed to clone wiki: %v", err) RemoveAllWithNotice("Delete repository wiki for initialization failure", wikiPath) } } @@ -813,7 +813,7 @@ func MigrateRepository(doer, owner *User, opts MigrateRepoOptions) (*Repository, } if err = repo.UpdateSize(); err != nil { - log.Error(2, "UpdateSize [repo_id: %d]: %v", repo.ID, err) + log.Error("UpdateSize [repo_id: %d]: %v", repo.ID, err) } } @@ -1163,7 +1163,7 @@ func countRepositories(userID int64, private bool) int64 { count, err := sess.Count(new(Repository)) if err != nil { - log.Error(4, "countRepositories: %v", err) + log.Error("countRepositories: %v", err) } return count } @@ -1436,11 +1436,11 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e daemonExportFile := path.Join(repo.RepoPath(), "git-daemon-export-ok") if repo.IsPrivate && com.IsExist(daemonExportFile) { if err = os.Remove(daemonExportFile); err != nil { - log.Error(4, "Failed to remove %s: %v", daemonExportFile, err) + log.Error("Failed to remove %s: %v", daemonExportFile, err) } } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) { if f, err := os.Create(daemonExportFile); err != nil { - log.Error(4, "Failed to create %s: %v", daemonExportFile, err) + log.Error("Failed to create %s: %v", daemonExportFile, err) } else { f.Close() } @@ -1592,7 +1592,7 @@ func DeleteRepository(uid, repoID int64) error { if repo.NumForks > 0 { if _, err = x.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil { - log.Error(4, "reset 'fork_id' and 'is_fork': %v", err) + log.Error("reset 'fork_id' and 'is_fork': %v", err) } } @@ -1781,14 +1781,14 @@ func DeleteOldRepositoryArchives() { dir, err := os.Open(dirPath) if err != nil { - log.Error(3, "Fail to open directory '%s': %v", dirPath, err) + log.Error("Failed to open directory '%s': %v", dirPath, err) continue } fis, err := dir.Readdir(0) dir.Close() if err != nil { - log.Error(3, "Fail to read directory '%s': %v", dirPath, err) + log.Error("Failed to read directory '%s': %v", dirPath, err) continue } @@ -1799,10 +1799,10 @@ func DeleteOldRepositoryArchives() { archivePath := filepath.Join(dirPath, fi.Name()) if err = os.Remove(archivePath); err != nil { - desc := fmt.Sprintf("Fail to health delete archive '%s': %v", archivePath, err) + desc := fmt.Sprintf("Failed to health delete archive '%s': %v", archivePath, err) log.Warn(desc) if err = CreateRepositoryNotice(desc); err != nil { - log.Error(3, "CreateRepositoryNotice: %v", err) + log.Error("CreateRepositoryNotice: %v", err) } } } @@ -1810,7 +1810,7 @@ func DeleteOldRepositoryArchives() { return nil }); err != nil { - log.Error(2, "DeleteOldRepositoryArchives: %v", err) + log.Error("DeleteOldRepositoryArchives: %v", err) } } @@ -1935,12 +1935,12 @@ func GitFsck() { desc := fmt.Sprintf("Failed to perform health check on repository '%s': %v", repoPath, err) log.Warn(desc) if err = CreateRepositoryNotice(desc); err != nil { - log.Error(3, "CreateRepositoryNotice: %v", err) + log.Error("CreateRepositoryNotice: %v", err) } } return nil }); err != nil { - log.Error(2, "GitFsck: %v", err) + log.Error("GitFsck: %v", err) } } @@ -1971,7 +1971,7 @@ type repoChecker struct { func repoStatsCheck(checker *repoChecker) { results, err := x.Query(checker.querySQL) if err != nil { - log.Error(2, "Select %s: %v", checker.desc, err) + log.Error("Select %s: %v", checker.desc, err) return } for _, result := range results { @@ -1979,7 +1979,7 @@ func repoStatsCheck(checker *repoChecker) { log.Trace("Updating %s: %d", checker.desc, id) _, err = x.Exec(checker.correctSQL, id, id) if err != nil { - log.Error(2, "Update %s[%d]: %v", checker.desc, id, err) + log.Error("Update %s[%d]: %v", checker.desc, id, err) } } } @@ -2033,14 +2033,14 @@ func CheckRepoStats() { desc := "repository count 'num_closed_issues'" results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false) if err != nil { - log.Error(2, "Select %s: %v", desc, err) + log.Error("Select %s: %v", desc, err) } else { for _, result := range results { id := com.StrTo(result["id"]).MustInt64() log.Trace("Updating %s: %d", desc, id) _, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, false, id) if err != nil { - log.Error(2, "Update %s[%d]: %v", desc, id, err) + log.Error("Update %s[%d]: %v", desc, id, err) } } } @@ -2050,7 +2050,7 @@ func CheckRepoStats() { // ***** START: Repository.NumForks ***** results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)") if err != nil { - log.Error(2, "Select repository count 'num_forks': %v", err) + log.Error("Select repository count 'num_forks': %v", err) } else { for _, result := range results { id := com.StrTo(result["id"]).MustInt64() @@ -2058,19 +2058,19 @@ func CheckRepoStats() { repo, err := GetRepositoryByID(id) if err != nil { - log.Error(2, "GetRepositoryByID[%d]: %v", id, err) + log.Error("GetRepositoryByID[%d]: %v", id, err) continue } rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID) if err != nil { - log.Error(2, "Select count of forks[%d]: %v", repo.ID, err) + log.Error("Select count of forks[%d]: %v", repo.ID, err) continue } repo.NumForks = int(parseCountResult(rawResult)) if err = UpdateRepository(repo, false); err != nil { - log.Error(2, "UpdateRepository[%d]: %v", id, err) + log.Error("UpdateRepository[%d]: %v", id, err) continue } } @@ -2410,14 +2410,14 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string) } if err = repo.UpdateSize(); err != nil { - log.Error(2, "UpdateSize [repo_id: %d]: %v", repo.ID, err) + log.Error("UpdateSize [repo_id: %d]: %v", repo.ID, err) } if err = PrepareWebhooks(baseRepo, HOOK_EVENT_FORK, &api.ForkPayload{ Forkee: repo.APIFormat(nil), Repo: baseRepo.APIFormat(nil), Sender: doer.APIFormat(), }); err != nil { - log.Error(2, "PrepareWebhooks [repo_id: %d]: %v", baseRepo.ID, err) + log.Error("PrepareWebhooks [repo_id: %d]: %v", baseRepo.ID, err) } return repo, nil } diff --git a/internal/db/repo_collaboration.go b/internal/db/repo_collaboration.go index 84059c0a..b3d046ec 100644 --- a/internal/db/repo_collaboration.go +++ b/internal/db/repo_collaboration.go @@ -7,7 +7,7 @@ package db import ( "fmt" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" api "github.com/gogs/go-gogs-client" ) @@ -41,7 +41,7 @@ func IsCollaborator(repoID, userID int64) bool { } has, err := x.Get(collaboration) if err != nil { - log.Error(2, "get collaboration [repo_id: %d, user_id: %d]: %v", repoID, userID, err) + log.Error("get collaboration [repo_id: %d, user_id: %d]: %v", repoID, userID, err) return false } return has diff --git a/internal/db/ssh_key.go b/internal/db/ssh_key.go index 317d90d3..d4189cff 100644 --- a/internal/db/ssh_key.go +++ b/internal/db/ssh_key.go @@ -20,7 +20,7 @@ import ( "github.com/unknwon/com" "golang.org/x/crypto/ssh" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "gogs.io/gogs/internal/process" @@ -341,7 +341,7 @@ func appendAuthorizedKeysToFile(keys ...*PublicKey) error { // .ssh directory should have mode 700, and authorized_keys file should have mode 600. if fi.Mode().Perm() > 0600 { - log.Error(4, "authorized_keys file has unusual permission flags: %s - setting to -rw-------", fi.Mode().Perm().String()) + log.Error("authorized_keys file has unusual permission flags: %s - setting to -rw-------", fi.Mode().Perm().String()) if err = f.Chmod(0600); err != nil { return err } diff --git a/internal/db/ssh_key_test.go b/internal/db/ssh_key_test.go index d4c06488..616347fb 100644 --- a/internal/db/ssh_key_test.go +++ b/internal/db/ssh_key_test.go @@ -15,7 +15,7 @@ import ( ) func init() { - setting.NewContext() + setting.Init() } func Test_SSHParsePublicKey(t *testing.T) { diff --git a/internal/db/two_factor.go b/internal/db/two_factor.go index dcc1c16c..cb539ef6 100644 --- a/internal/db/two_factor.go +++ b/internal/db/two_factor.go @@ -12,7 +12,7 @@ import ( "github.com/pquerna/otp/totp" "github.com/unknwon/com" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "gogs.io/gogs/internal/db/errors" @@ -58,7 +58,7 @@ func (t *TwoFactor) ValidateTOTP(passcode string) (bool, error) { func IsUserEnabledTwoFactor(userID int64) bool { has, err := x.Where("user_id = ?", userID).Get(new(TwoFactor)) if err != nil { - log.Error(2, "IsUserEnabledTwoFactor [user_id: %d]: %v", userID, err) + log.Error("IsUserEnabledTwoFactor [user_id: %d]: %v", userID, err) } return has } diff --git a/internal/db/update.go b/internal/db/update.go index 6555a479..e8fc41ed 100644 --- a/internal/db/update.go +++ b/internal/db/update.go @@ -67,7 +67,7 @@ func PushUpdate(opts PushUpdateOptions) (err error) { gitUpdate := exec.Command("git", "update-server-info") gitUpdate.Dir = repoPath if err = gitUpdate.Run(); err != nil { - return fmt.Errorf("Fail to call 'git update-server-info': %v", err) + return fmt.Errorf("run 'git update-server-info': %v", err) } gitRepo, err := git.OpenRepository(repoPath) diff --git a/internal/db/user.go b/internal/db/user.go index 003e2efd..ad6448aa 100644 --- a/internal/db/user.go +++ b/internal/db/user.go @@ -23,7 +23,7 @@ import ( "github.com/nfnt/resize" "github.com/unknwon/com" "golang.org/x/crypto/pbkdf2" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" "github.com/gogs/git-module" @@ -265,7 +265,7 @@ func (u *User) RelAvatarLink() string { case setting.DisableGravatar, setting.OfflineMode: if !com.IsExist(u.CustomAvatarPath()) { if err := u.GenerateRandomAvatar(); err != nil { - log.Error(3, "GenerateRandomAvatar: %v", err) + log.Error("GenerateRandomAvatar: %v", err) } } @@ -371,7 +371,7 @@ func (u *User) DeleteAvatar() error { func (u *User) IsAdminOfRepo(repo *Repository) bool { has, err := HasAccess(u.ID, repo, ACCESS_MODE_ADMIN) if err != nil { - log.Error(2, "HasAccess: %v", err) + log.Error("HasAccess: %v", err) } return has } @@ -380,7 +380,7 @@ func (u *User) IsAdminOfRepo(repo *Repository) bool { func (u *User) IsWriterOfRepo(repo *Repository) bool { has, err := HasAccess(u.ID, repo, ACCESS_MODE_WRITE) if err != nil { - log.Error(2, "HasAccess: %v", err) + log.Error("HasAccess: %v", err) } return has } @@ -608,7 +608,7 @@ func parseUserFromCode(code string) (user *User) { if user, err = GetUserByName(string(b)); user != nil { return user } else if !errors.IsUserNotExist(err) { - log.Error(2, "GetUserByName: %v", err) + log.Error("GetUserByName: %v", err) } } diff --git a/internal/db/webhook.go b/internal/db/webhook.go index 750cc613..7bbdac0e 100644 --- a/internal/db/webhook.go +++ b/internal/db/webhook.go @@ -16,7 +16,7 @@ import ( "github.com/json-iterator/go" gouuid "github.com/satori/go.uuid" - log "gopkg.in/clog.v1" + log "unknwon.dev/clog/v2" "xorm.io/xorm" api "github.com/gogs/go-gogs-client" @@ -127,7 +127,7 @@ func (w *Webhook) AfterSet(colName string, _ xorm.Cell) { case "events": w.HookEvent = &HookEvent{} if err = jsoniter.Unmarshal([]byte(w.Events), w.HookEvent); err != nil { - log.Error(3, "Unmarshal [%d]: %v", w.ID, err) + log.Error("Unmarshal [%d]: %v", w.ID, err) } case "created_unix": w.Created = time.Unix(w.CreatedUnix, 0).Local() @@ -139,7 +139,7 @@ func (w *Webhook) AfterSet(colName string, _ xorm.Cell) { func (w *Webhook) GetSlackHook() *SlackMeta { s := &SlackMeta{} if err := jsoniter.Unmarshal([]byte(w.Meta), s); err != nil { - log.Error(2, "GetSlackHook [%d]: %v", w.ID, err) + log.Error("GetSlackHook [%d]: %v", w.ID, err) } return s } @@ -457,7 +457,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) { t.RequestInfo = &HookRequest{} if err = jsoniter.Unmarshal([]byte(t.RequestContent), t.RequestInfo); err != nil { - log.Error(3, "Unmarshal[%d]: %v", t.ID, err) + log.Error("Unmarshal[%d]: %v", t.ID, err) } case "response_content": @@ -467,7 +467,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) { t.ResponseInfo = &HookResponse{} if err = jsoniter.Unmarshal([]byte(t.ResponseContent), t.ResponseInfo); err != nil { - log.Error(3, "Unmarshal [%d]: %v", t.ID, err) + log.Error("Unmarshal [%d]: %v", t.ID, err) } } } @@ -475,7 +475,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) { func (t *HookTask) MarshalJSON(v interface{}) string { p, err := jsoniter.Marshal(v) if err != nil { - log.Error(3, "Marshal [%d]: %v", t.ID, err) + log.Error("Marshal [%d]: %v", t.ID, err) } return string(p) } @@ -588,7 +588,7 @@ func prepareHookTasks(e Engine, repo *Repository, event HookEventType, p api.Pay if len(w.Secret) > 0 { data, err := payloader.JSONPayload() if err != nil { - log.Error(2, "prepareWebhooks.JSONPayload: %v", err) + log.Error("prepareWebhooks.JSONPayload: %v", err) } sig := hmac.New(sha256.New, []byte(w.Secret)) sig.Write(data) @@ -691,7 +691,7 @@ func (t *HookTask) deliver() { // Update webhook last delivery status. w, err := GetWebhookByID(t.HookID) if err != nil { - log.Error(3, "GetWebhookByID: %v", err) + log.Error("GetWebhookByID: %v", err) return } if t.IsSucceed { @@ -700,7 +700,7 @@ func (t *HookTask) deliver() { w.LastStatus = HOOK_STATUS_FAILED } if err = UpdateWebhook(w); err != nil { - log.Error(3, "UpdateWebhook: %v", err) + log.Error("UpdateWebhook: %v", err) return } }() @@ -742,7 +742,7 @@ func DeliverHooks() { // Update hook task status. for _, t := range tasks { if err := UpdateHookTask(t); err != nil { - log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err) + log.Error("UpdateHookTask [%d]: %v", t.ID, err) } } @@ -753,13 +753,13 @@ func DeliverHooks() { tasks = make([]*HookTask, 0, 5) if err := x.Where("repo_id = ?", repoID).And("is_delivered = ?", false).Find(&tasks); err != nil { - log.Error(4, "Get repository [%s] hook tasks: %v", repoID, err) + log.Error("Get repository [%s] hook tasks: %v", repoID, err) continue } for _, t := range tasks { t.deliver() if err := UpdateHookTask(t); err != nil { - log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err) + log.Error("UpdateHookTask [%d]: %v", t.ID, err) continue } } |