mirror of
1
Fork 0

Fix bug related to log

This commit is contained in:
Unknown 2014-04-06 13:07:34 -04:00
parent cd5b800a21
commit 794cd27db3
3 changed files with 23 additions and 40 deletions

View File

@ -19,7 +19,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true
const APP_VER = "0.2.1.0405 Alpha"
const APP_VER = "0.2.1.0406 Alpha"
func init() {
base.AppVer = APP_VER

View File

@ -14,7 +14,7 @@ import (
"strings"
"github.com/codegangsta/cli"
"github.com/gogits/gogs/modules/log"
qlog "github.com/qiniu/log"
//"github.com/gogits/git"
"github.com/gogits/gogs/models"
@ -44,11 +44,15 @@ gogs serv provide access auth for repositories`,
}
func newLogger(execDir string) {
level := "0"
logPath := execDir + "/log/serv.log"
os.MkdirAll(path.Dir(logPath), os.ModePerm)
log.NewLogger(0, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, logPath))
log.Trace("start logging...")
f, err := os.Open(logPath)
if err != nil {
qlog.Fatal(err)
}
qlog.SetOutput(f)
qlog.Info("Start logging serv...")
}
func parseCmd(cmd string) (string, string) {
@ -87,21 +91,18 @@ func runServ(k *cli.Context) {
keys := strings.Split(os.Args[2], "-")
if len(keys) != 2 {
println("auth file format error")
log.Error("auth file format error")
return
qlog.Fatal("auth file format error")
}
keyId, err := strconv.ParseInt(keys[1], 10, 64)
if err != nil {
println("auth file format error")
log.Error("auth file format error", err)
return
qlog.Fatal("auth file format error", err)
}
user, err := models.GetUserByKeyId(keyId)
if err != nil {
println("You have no right to access")
log.Error("SSH visit error: %v", err)
return
qlog.Fatalf("SSH visit error: %v", err)
}
cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
@ -115,8 +116,7 @@ func runServ(k *cli.Context) {
rr := strings.SplitN(repoPath, "/", 2)
if len(rr) != 2 {
println("Unavilable repository", args)
log.Error("Unavilable repository %v", args)
return
qlog.Fatalf("Unavilable repository %v", args)
}
repoUserName := rr[0]
repoName := rr[1]
@ -129,9 +129,8 @@ func runServ(k *cli.Context) {
repoUser, err := models.GetUserByName(repoUserName)
if err != nil {
fmt.Println("You have no right to access")
log.Error("Get user failed", err)
return
println("You have no right to access")
qlog.Fatal("Get user failed", err)
}
// access check
@ -140,19 +139,16 @@ func runServ(k *cli.Context) {
has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE)
if err != nil {
println("Inernel error:", err)
log.Error(err.Error())
return
qlog.Fatal(err)
} else if !has {
println("You have no right to write this repository")
log.Error("User %s has no right to write repository %s", user.Name, repoPath)
return
qlog.Fatalf("User %s has no right to write repository %s", user.Name, repoPath)
}
case isRead:
repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
if err != nil {
println("Get repository error:", err)
log.Error("Get repository error: " + err.Error())
return
qlog.Fatal("Get repository error: " + err.Error())
}
if !repo.IsPrivate {
@ -162,26 +158,22 @@ func runServ(k *cli.Context) {
has, err := models.HasAccess(user.Name, repoPath, models.AU_READABLE)
if err != nil {
println("Inernel error")
log.Error(err.Error())
return
qlog.Fatal(err)
}
if !has {
has, err = models.HasAccess(user.Name, repoPath, models.AU_WRITABLE)
if err != nil {
println("Inernel error")
log.Error(err.Error())
return
qlog.Fatal(err)
}
}
if !has {
println("You have no right to access this repository")
log.Error("You have no right to access this repository")
return
qlog.Fatal("You have no right to access this repository")
}
default:
println("Unknown command")
log.Error("Unknown command")
return
qlog.Fatal("Unknown command")
}
// for update use
@ -197,7 +189,6 @@ func runServ(k *cli.Context) {
if err = gitcmd.Run(); err != nil {
println("execute command error:", err.Error())
log.Error("execute command error: " + err.Error())
return
qlog.Fatal("execute command error: " + err.Error())
}
}

View File

@ -92,13 +92,11 @@ func runUpdate(c *cli.Context) {
newOid, err := git.NewOidFromString(newCommitId)
if err != nil {
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
return
}
newCommit, err := repo.LookupCommit(newOid)
if err != nil {
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
return
}
var l *list.List
@ -107,38 +105,32 @@ func runUpdate(c *cli.Context) {
l, err = repo.CommitsBefore(newCommit.Id())
if err != nil {
qlog.Fatalf("Find CommitsBefore erro:", err)
return
}
} else {
oldOid, err := git.NewOidFromString(oldCommitId)
if err != nil {
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
return
}
oldCommit, err := repo.LookupCommit(oldOid)
if err != nil {
qlog.Fatalf("runUpdate.Ref repoId: %v", err)
return
}
l = repo.CommitsBetween(newCommit, oldCommit)
}
if err != nil {
qlog.Fatalf("runUpdate.Commit repoId: %v", err)
return
}
sUserId, err := strconv.Atoi(userId)
if err != nil {
qlog.Fatalf("runUpdate.Parse userId: %v", err)
return
}
repos, err := models.GetRepositoryByName(int64(sUserId), repoName)
if err != nil {
qlog.Fatalf("runUpdate.GetRepositoryByName userId: %v", err)
return
}
commits := make([]*base.PushCommit, 0)