1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-24 02:18:28 +00:00

Better logging (#6038) (#6095)

* Panic don't fatal on create new logger

Fixes #5854

Signed-off-by: Andrew Thornton <art27@cantab.net>

* partial broken

* Update the logging infrastrcture

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Reset the skip levels for Fatal and Error

Signed-off-by: Andrew Thornton <art27@cantab.net>

* broken ncsa

* More log.Error fixes

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Remove nal

* set log-levels to lowercase

* Make console_test test all levels

* switch to lowercased levels

* OK now working

* Fix vetting issues

* Fix lint

* Fix tests

* change default logging to match current gitea

* Improve log testing

Signed-off-by: Andrew Thornton <art27@cantab.net>

* reset error skip levels to 0

* Update documentation and access logger configuration

* Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE

* Fix broken level caching

* Refactor the router log

* Add Router logger

* Add colorizing options

* Adjust router colors

* Only create logger if they will be used

* update app.ini.sample

* rename Attribute ColorAttribute

* Change from white to green for function

* Set fatal/error levels

* Restore initial trace logger

* Fix Trace arguments in modules/auth/auth.go

* Properly handle XORMLogger

* Improve admin/config page

* fix fmt

* Add auto-compression of old logs

* Update error log levels

* Remove the unnecessary skip argument from Error, Fatal and Critical

* Add stacktrace support

* Fix tests

* Remove x/sync from vendors?

* Add stderr option to console logger

* Use filepath.ToSlash to protect against Windows in tests

* Remove prefixed underscores from names in colors.go

* Remove not implemented database logger

This was removed from Gogs on 4 Mar 2016 but left in the configuration
since then.

* Ensure that log paths are relative to ROOT_PATH

* use path.Join

* rename jsonConfig to logConfig

* Rename "config" to "jsonConfig" to make it clearer

* Requested changes

* Requested changes: XormLogger

* Try to color the windows terminal

If successful default to colorizing the console logs

* fixup

* Colorize initially too

* update vendor

* Colorize logs on default and remove if this is not a colorizing logger

* Fix documentation

* fix test

* Use go-isatty to detect if on windows we are on msys or cygwin

* Fix spelling mistake

* Add missing vendors

* More changes

* Rationalise the ANSI writer protection

* Adjust colors on advice from @0x5c

* Make Flags a comma separated list

* Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING

* Ensure matching is done on the non-colored message - to simpify EXPRESSION
This commit is contained in:
zeripath
2019-04-02 08:48:31 +01:00
committed by GitHub
parent ef2a343e27
commit 704da08fdc
301 changed files with 36993 additions and 8244 deletions

View File

@@ -51,7 +51,7 @@ func DeleteBranchPost(ctx *context.Context) {
branchName := ctx.Query("name")
isProtected, err := ctx.Repo.Repository.IsProtectedBranch(branchName, ctx.User)
if err != nil {
log.Error(4, "DeleteBranch: %v", err)
log.Error("DeleteBranch: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", branchName))
return
}
@@ -83,7 +83,7 @@ func RestoreBranchPost(ctx *context.Context) {
deletedBranch, err := ctx.Repo.Repository.GetDeletedBranchByID(branchID)
if err != nil {
log.Error(4, "GetDeletedBranchByID: %v", err)
log.Error("GetDeletedBranchByID: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName))
return
}
@@ -93,13 +93,13 @@ func RestoreBranchPost(ctx *context.Context) {
ctx.Flash.Error(ctx.Tr("repo.branch.already_exists", deletedBranch.Name))
return
}
log.Error(4, "CreateBranch: %v", err)
log.Error("CreateBranch: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name))
return
}
if err := ctx.Repo.Repository.RemoveDeletedBranch(deletedBranch.ID); err != nil {
log.Error(4, "RemoveDeletedBranch: %v", err)
log.Error("RemoveDeletedBranch: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name))
return
}
@@ -116,14 +116,14 @@ func redirect(ctx *context.Context) {
func deleteBranch(ctx *context.Context, branchName string) error {
commit, err := ctx.Repo.GitRepo.GetBranchCommit(branchName)
if err != nil {
log.Error(4, "GetBranchCommit: %v", err)
log.Error("GetBranchCommit: %v", err)
return err
}
if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
Force: true,
}); err != nil {
log.Error(4, "DeleteBranch: %v", err)
log.Error("DeleteBranch: %v", err)
return err
}
@@ -137,7 +137,7 @@ func deleteBranch(ctx *context.Context, branchName string) error {
RepoUserName: ctx.Repo.Owner.Name,
RepoName: ctx.Repo.Repository.Name,
}); err != nil {
log.Error(4, "Update: %v", err)
log.Error("Update: %v", err)
}
if err := ctx.Repo.Repository.AddDeletedBranch(branchName, commit.ID.String(), ctx.User.ID); err != nil {

View File

@@ -203,7 +203,7 @@ func Diff(ctx *context.Context) {
statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository, commitID, 0)
if err != nil {
log.Error(3, "GetLatestCommitStatus: %v", err)
log.Error("GetLatestCommitStatus: %v", err)
}
ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses)

View File

@@ -35,7 +35,7 @@ const (
func renderCommitRights(ctx *context.Context) bool {
canCommit, err := ctx.Repo.CanCommitToBranch(ctx.User)
if err != nil {
log.Error(4, "CanCommitToBranch: %v", err)
log.Error("CanCommitToBranch: %v", err)
}
ctx.Data["CanCommitToBranch"] = canCommit
return canCommit
@@ -117,7 +117,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
buf = append(buf, d...)
if content, err := templates.ToUTF8WithErr(buf); err != nil {
if err != nil {
log.Error(4, "ToUTF8WithErr: %v", err)
log.Error("ToUTF8WithErr: %v", err)
}
ctx.Data["FileContent"] = string(buf)
} else {

View File

@@ -181,7 +181,7 @@ func HTTP(ctx *context.Context) {
}
} else {
if !models.IsErrAccessTokenNotExist(err) && !models.IsErrAccessTokenEmpty(err) {
log.Error(4, "GetAccessTokenBySha: %v", err)
log.Error("GetAccessTokenBySha: %v", err)
}
}
@@ -324,7 +324,7 @@ func gitCommand(dir string, args ...string) []byte {
cmd.Dir = dir
out, err := cmd.Output()
if err != nil {
log.GitLogger.Error(4, fmt.Sprintf("%v - %s", err, out))
log.GitLogger.Error(fmt.Sprintf("%v - %s", err, out))
}
return out
}
@@ -382,7 +382,7 @@ func serviceRPC(h serviceHandler, service string) {
if h.r.Header.Get("Content-Encoding") == "gzip" {
reqBody, err = gzip.NewReader(reqBody)
if err != nil {
log.GitLogger.Error(2, "fail to create gzip reader: %v", err)
log.GitLogger.Error("Fail to create gzip reader: %v", err)
h.w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -401,7 +401,7 @@ func serviceRPC(h serviceHandler, service string) {
cmd.Stdin = reqBody
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
log.GitLogger.Error(2, "fail to serve RPC(%s): %v - %v", service, err, stderr)
log.GitLogger.Error("Fail to serve RPC(%s): %v - %v", service, err, stderr)
return
}
}
@@ -514,7 +514,7 @@ func HTTPBackend(ctx *context.Context, cfg *serviceConfig) http.HandlerFunc {
file := strings.Replace(r.URL.Path, m[1]+"/", "", 1)
dir, err := getGitRepoPath(m[1])
if err != nil {
log.GitLogger.Error(4, err.Error())
log.GitLogger.Error(err.Error())
ctx.NotFound("HTTPBackend", err)
return
}

View File

@@ -408,7 +408,7 @@ func NewIssue(ctx *context.Context) {
milestoneID := ctx.QueryInt64("milestone")
milestone, err := models.GetMilestoneByID(milestoneID)
if err != nil {
log.Error(4, "GetMilestoneByID: %d: %v", milestoneID, err)
log.Error("GetMilestoneByID: %d: %v", milestoneID, err)
} else {
ctx.Data["milestone_id"] = milestoneID
ctx.Data["Milestone"] = milestone
@@ -847,7 +847,7 @@ func ViewIssue(ctx *context.Context) {
if ctx.IsSigned {
if err := pull.GetHeadRepo(); err != nil {
log.Error(4, "GetHeadRepo: %v", err)
log.Error("GetHeadRepo: %v", err)
} else if pull.HeadRepo != nil && pull.HeadBranch != pull.HeadRepo.DefaultBranch {
perm, err := models.GetUserRepoPermission(pull.HeadRepo, ctx.User)
if err != nil {
@@ -857,7 +857,7 @@ func ViewIssue(ctx *context.Context) {
if perm.CanWrite(models.UnitTypeCode) {
// Check if branch is not protected
if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch, ctx.User); err != nil {
log.Error(4, "IsProtectedBranch: %v", err)
log.Error("IsProtectedBranch: %v", err)
} else if !protected {
canDelete = true
ctx.Data["DeleteBranchLink"] = ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index) + "/cleanup"
@@ -1204,7 +1204,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
} else {
isClosed := form.Status == "close"
if err := issue.ChangeStatus(ctx.User, isClosed); err != nil {
log.Error(4, "ChangeStatus: %v", err)
log.Error("ChangeStatus: %v", err)
if models.IsErrDependenciesLeft(err) {
if issue.IsPull {

View File

@@ -1058,7 +1058,7 @@ func CleanUpPullRequest(ctx *context.Context) {
// Check if branch is not protected
if protected, err := pr.HeadRepo.IsProtectedBranch(pr.HeadBranch, ctx.User); err != nil || protected {
if err != nil {
log.Error(4, "HeadRepo.IsProtectedBranch: %v", err)
log.Error("HeadRepo.IsProtectedBranch: %v", err)
}
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
return
@@ -1067,13 +1067,13 @@ func CleanUpPullRequest(ctx *context.Context) {
// Check if branch has no new commits
headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
log.Error(4, "GetRefCommitID: %v", err)
log.Error("GetRefCommitID: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
return
}
branchCommitID, err := gitRepo.GetBranchCommitID(pr.HeadBranch)
if err != nil {
log.Error(4, "GetBranchCommitID: %v", err)
log.Error("GetBranchCommitID: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
return
}
@@ -1085,14 +1085,14 @@ func CleanUpPullRequest(ctx *context.Context) {
if err := gitRepo.DeleteBranch(pr.HeadBranch, git.DeleteBranchOptions{
Force: true,
}); err != nil {
log.Error(4, "DeleteBranch: %v", err)
log.Error("DeleteBranch: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
return
}
if err := models.AddDeletePRBranchComment(ctx.User, pr.BaseRepo, issue.ID, pr.HeadBranch); err != nil {
// Do not fail here as branch has already been deleted
log.Error(4, "DeleteBranch: %v", err)
log.Error("DeleteBranch: %v", err)
}
ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName))

View File

@@ -182,7 +182,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
if repo != nil {
if errDelete := models.DeleteRepository(ctx.User, ctxUser.ID, repo.ID); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete)
log.Error("DeleteRepository: %v", errDelete)
}
}
@@ -265,7 +265,7 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
if repo != nil {
if errDelete := models.DeleteRepository(ctx.User, ctxUser.ID, repo.ID); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete)
log.Error("DeleteRepository: %v", errDelete)
}
}

View File

@@ -110,7 +110,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
if isNameChanged {
if err := models.RenameRepoAction(ctx.User, oldRepoName, repo); err != nil {
log.Error(4, "RenameRepoAction: %v", err)
log.Error("RenameRepoAction: %v", err)
}
}
@@ -398,7 +398,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
}
if err := repo.SetArchiveRepoState(true); err != nil {
log.Error(4, "Tried to archive a repo: %s", err)
log.Error("Tried to archive a repo: %s", err)
ctx.Flash.Error(ctx.Tr("repo.settings.archive.error"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
return
@@ -415,7 +415,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
}
if err := repo.SetArchiveRepoState(false); err != nil {
log.Error(4, "Tried to unarchive a repo: %s", err)
log.Error("Tried to unarchive a repo: %s", err)
ctx.Flash.Error(ctx.Tr("repo.settings.unarchive.error"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
return
@@ -502,7 +502,7 @@ func ChangeCollaborationAccessMode(ctx *context.Context) {
if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(
ctx.QueryInt64("uid"),
models.AccessMode(ctx.QueryInt("mode"))); err != nil {
log.Error(4, "ChangeCollaborationAccessMode: %v", err)
log.Error("ChangeCollaborationAccessMode: %v", err)
}
}

View File

@@ -60,7 +60,7 @@ func TopicsPost(ctx *context.Context) {
err := models.SaveTopics(ctx.Repo.Repository.ID, topics...)
if err != nil {
log.Error(2, "SaveTopics failed: %v", err)
log.Error("SaveTopics failed: %v", err)
ctx.JSON(500, map[string]interface{}{
"message": "Save topics failed.",
})

View File

@@ -192,7 +192,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository, ctx.Repo.Commit.ID.String(), 0)
if err != nil {
log.Error(3, "GetLatestCommitStatus: %v", err)
log.Error("GetLatestCommitStatus: %v", err)
}
ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses)
@@ -304,7 +304,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
var fileContent string
if content, err := templates.ToUTF8WithErr(buf); err != nil {
if err != nil {
log.Error(4, "ToUTF8WithErr: %v", err)
log.Error("ToUTF8WithErr: %v", err)
}
fileContent = string(buf)
} else {