summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-04-02 08:48:31 +0100
committerGitHub <noreply@github.com>2019-04-02 08:48:31 +0100
commit704da08fdc6bae6fdd6bf1b892ebe12afeef5eca (patch)
treee0613ab3ba0d4336b0912bbad8862f503ec180f6 /models/repo.go
parentef2a343e27d8af2de0bb696bd60d9a019e1e8b69 (diff)
downloadgitea-704da08fdc6bae6fdd6bf1b892ebe12afeef5eca.tar.gz
gitea-704da08fdc6bae6fdd6bf1b892ebe12afeef5eca.zip
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
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go64
1 files changed, 32 insertions, 32 deletions
diff --git a/models/repo.go b/models/repo.go
index 19526fb17c..5cdee6c3f9 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -74,13 +74,13 @@ func LoadRepoConfig() {
for i, t := range types {
files, err := options.Dir(t)
if err != nil {
- log.Fatal(4, "Failed to get %s files: %v", t, err)
+ log.Fatal("Failed to get %s files: %v", t, err)
}
customPath := path.Join(setting.CustomPath, "options", t)
if com.IsDir(customPath) {
customFiles, err := com.StatDir(customPath)
if err != nil {
- log.Fatal(4, "Failed to get custom %s files: %v", t, err)
+ log.Fatal("Failed to get custom %s files: %v", t, err)
}
for _, f := range customFiles {
@@ -122,19 +122,19 @@ func NewRepoContext() {
// Check Git installation.
if _, err := exec.LookPath("git"); err != nil {
- log.Fatal(4, "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(4, "Failed to get Git version: %v", err)
+ log.Fatal("Failed to get Git version: %v", err)
}
log.Info("Git Version: %s", setting.Git.Version)
if version.Compare("1.7.1", setting.Git.Version, ">") {
- log.Fatal(4, "Gitea requires Git version greater or equal to 1.7.1")
+ log.Fatal("Gitea requires Git version greater or equal to 1.7.1")
}
// Git requires setting user.name and user.email in order to commit changes.
@@ -143,11 +143,11 @@ func NewRepoContext() {
// ExitError indicates this config is not set
if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
if _, stderr, gerr := process.GetManager().Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
- log.Fatal(4, "Failed 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, "Failed to get git %s(%s): %s", configKey, err, stderr)
+ log.Fatal("Failed to get git %s(%s): %s", configKey, err, stderr)
}
}
}
@@ -155,7 +155,7 @@ func NewRepoContext() {
// Set git some configurations.
if _, stderr, err := process.GetManager().Exec("NewRepoContext(git config --global core.quotepath false)",
"git", "config", "--global", "core.quotepath", "false"); err != nil {
- log.Fatal(4, "Failed to execute 'git config --global core.quotepath false': %s", stderr)
+ log.Fatal("Failed to execute 'git config --global core.quotepath false': %s", stderr)
}
RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
@@ -281,7 +281,7 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
if !isParent {
err := repo.getBaseRepo(e)
if err != nil {
- log.Error(4, "APIFormat: %v", err)
+ log.Error("APIFormat: %v", err)
}
if repo.BaseRepo != nil {
parent = repo.BaseRepo.innerAPIFormat(e, mode, true)
@@ -462,7 +462,7 @@ func (repo *Repository) GetOwnerName() error {
func (repo *Repository) mustOwnerName(e Engine) string {
if err := repo.getOwnerName(e); err != nil {
- log.Error(4, "Error loading repository owner name: %v", err)
+ log.Error("Error loading repository owner name: %v", err)
return "error"
}
@@ -724,7 +724,7 @@ var (
func (repo *Repository) DescriptionHTML() template.HTML {
desc, err := markup.RenderDescriptionHTML([]byte(repo.Description), repo.HTMLURL(), repo.ComposeMetas())
if err != nil {
- log.Error(4, "Failed to render description for %s (ID: %d): %v", repo.Name, repo.ID, err)
+ log.Error("Failed to render description for %s (ID: %d): %v", repo.Name, repo.ID, err)
return template.HTML(markup.Sanitize(repo.Description))
}
return template.HTML(markup.Sanitize(string(desc)))
@@ -981,12 +981,12 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err
}
if err = SyncReleasesWithTags(repo, gitRepo); err != nil {
- log.Error(4, "Failed to synchronize tags to releases for repository: %v", err)
+ log.Error("Failed to synchronize tags to releases for repository: %v", err)
}
}
if err = repo.UpdateSize(); err != nil {
- log.Error(4, "Failed to update size for repository: %v", err)
+ log.Error("Failed to update size for repository: %v", err)
}
if opts.IsMirror {
@@ -1405,7 +1405,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
repoPath := RepoPath(u.Name, repo.Name)
if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
if err2 := os.RemoveAll(repoPath); err2 != nil {
- log.Error(4, "initRepository: %v", err)
+ log.Error("initRepository: %v", err)
return nil, fmt.Errorf(
"delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
}
@@ -1435,7 +1435,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
}
@@ -1690,11 +1690,11 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
daemonExportFile := path.Join(repo.repoPath(e), `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()
}
@@ -1712,7 +1712,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
}
if err = repo.updateSize(e); err != nil {
- log.Error(4, "Failed to update size for repository: %v", err)
+ log.Error("Failed to update size for repository: %v", err)
}
}
@@ -1928,7 +1928,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
if repo.NumForks > 0 {
if _, err = sess.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)
}
}
@@ -2090,7 +2090,7 @@ func DeleteOldRepositoryArchives() {
log.Trace("Doing: ArchiveCleanup")
if err := x.Where("id > 0").Iterate(new(Repository), deleteOldRepositoryArchives); err != nil {
- log.Error(4, "ArchiveClean: %v", err)
+ log.Error("ArchiveClean: %v", err)
}
}
@@ -2243,12 +2243,12 @@ func GitFsck() {
desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err)
log.Warn(desc)
if err = CreateRepositoryNotice(desc); err != nil {
- log.Error(4, "CreateRepositoryNotice: %v", err)
+ log.Error("CreateRepositoryNotice: %v", err)
}
}
return nil
}); err != nil {
- log.Error(4, "GitFsck: %v", err)
+ log.Error("GitFsck: %v", err)
}
log.Trace("Finished: GitFsck")
}
@@ -2283,7 +2283,7 @@ type repoChecker struct {
func repoStatsCheck(checker *repoChecker) {
results, err := x.Query(checker.querySQL)
if err != nil {
- log.Error(4, "Select %s: %v", checker.desc, err)
+ log.Error("Select %s: %v", checker.desc, err)
return
}
for _, result := range results {
@@ -2291,7 +2291,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(4, "Update %s[%d]: %v", checker.desc, id, err)
+ log.Error("Update %s[%d]: %v", checker.desc, id, err)
}
}
}
@@ -2345,14 +2345,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(4, "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(4, "Update %s[%d]: %v", desc, id, err)
+ log.Error("Update %s[%d]: %v", desc, id, err)
}
}
}
@@ -2362,7 +2362,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(4, "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()
@@ -2370,19 +2370,19 @@ func CheckRepoStats() {
repo, err := GetRepositoryByID(id)
if err != nil {
- log.Error(4, "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(4, "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(4, "UpdateRepository[%d]: %v", id, err)
+ log.Error("UpdateRepository[%d]: %v", id, err)
continue
}
}
@@ -2485,13 +2485,13 @@ func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *R
Repo: repo.APIFormat(mode),
Sender: doer.APIFormat(),
}); err != nil {
- log.Error(2, "PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
+ log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
} else {
go HookQueue.Add(oldRepo.ID)
}
if err = repo.UpdateSize(); err != nil {
- log.Error(4, "Failed to update size for repository: %v", err)
+ log.Error("Failed to update size for repository: %v", err)
}
// Copy LFS meta objects in new session