From a80603727db5a6871a833310bb47431e97628109 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 25 Mar 2014 17:52:03 +0800 Subject: [PATCH] add log --- serve.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/serve.go b/serve.go index 480b122f..8d9fd69c 100644 --- a/serve.go +++ b/serve.go @@ -48,6 +48,7 @@ gogs serv provide access auth for repositories`, func init() { os.MkdirAll("log", os.ModePerm) log.NewLogger(10000, "file", fmt.Sprintf(`{"filename":"%s"}`, "log/serv.log")) + log.Info("start logging...") } func parseCmd(cmd string) (string, string) { @@ -124,6 +125,7 @@ func runServ(k *cli.Context) { } } else { println("Get repository error:", err) + log.Error(err.Error()) return } } @@ -134,6 +136,7 @@ func runServ(k *cli.Context) { has, err := models.HasAccess(user.Name, repoName, models.AU_WRITABLE) if err != nil { println("Inernel error:", err) + log.Error(err.Error()) return } if !has { @@ -144,12 +147,14 @@ func runServ(k *cli.Context) { has, err := models.HasAccess(user.Name, repoName, models.AU_READABLE) if err != nil { println("Inernel error") + log.Error(err.Error()) return } if !has { has, err = models.HasAccess(user.Name, repoName, models.AU_WRITABLE) if err != nil { println("Inernel error") + log.Error(err.Error()) return } } @@ -169,6 +174,7 @@ func runServ(k *cli.Context) { _, err = models.CreateRepository(user, repoName, "", "", "", false, true) if err != nil { println("Create repository failed") + log.Error(err.Error()) return } } @@ -177,12 +183,14 @@ func runServ(k *cli.Context) { rep, err = git.OpenRepository(repoPath) if err != nil { println(err.Error()) + log.Error(err.Error()) return } refs, err := rep.AllReferencesMap() if err != nil { println(err.Error()) + log.Error(err.Error()) return } @@ -199,6 +207,7 @@ func runServ(k *cli.Context) { if err = gitcmd.Run(); err != nil { println("execute command error:", err.Error()) + log.Error(err.Error()) return } @@ -238,15 +247,17 @@ func runServ(k *cli.Context) { refs, err = rep.AllReferencesMap() if err != nil { println(err.Error()) + log.Error(err.Error()) return } if ref, ok = refs[refname]; !ok { - log.Trace("unknow reference name -", refname, "-", b.String()) + log.Error("unknow reference name -", refname, "-", b.String()) return } l, err = ref.AllCommits() if err != nil { println(err.Error()) + log.Error(err.Error()) return } } else { @@ -256,12 +267,14 @@ func runServ(k *cli.Context) { last, err = ref.LastCommit() if err != nil { println(err.Error()) + log.Error(err.Error()) return } ref2, err := rep.LookupReference(ref.Name) if err != nil { println(err.Error()) + log.Error(err.Error()) return } @@ -269,6 +282,7 @@ func runServ(k *cli.Context) { before, err := ref2.LastCommit() if err != nil { println(err.Error()) + log.Error(err.Error()) return } //log.Info("----", before.Id(), "-----", last.Id())