Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output error and warning log #717

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func doFile(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, fileID
err := blockmgr.Read(repo.StoreID, blkID, rsp)
if err != nil {
if !isNetworkErr(err) {
log.Printf("failed to read block %s: %v", blkID, err)
log.Errorf("failed to read block %s: %v", blkID, err)
}
return nil
}
Expand Down Expand Up @@ -523,7 +523,7 @@ func doFileRange(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, f
err := blockmgr.Read(repo.StoreID, blkID, &buf)
if err != nil {
if !isNetworkErr(err) {
log.Printf("failed to read block %s: %v", blkID, err)
log.Errorf("failed to read block %s: %v", blkID, err)
}
return nil
}
Expand All @@ -535,7 +535,7 @@ func doFileRange(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, f
err := blockmgr.Read(repo.StoreID, blkID, &buf)
if err != nil {
if !isNetworkErr(err) {
log.Printf("failed to read block %s: %v", blkID, err)
log.Errorf("failed to read block %s: %v", blkID, err)
}
return nil
}
Expand All @@ -557,7 +557,7 @@ func doFileRange(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, f
err := blockmgr.Read(repo.StoreID, blkID, &buf)
if err != nil {
if !isNetworkErr(err) {
log.Printf("failed to read block %s: %v", blkID, err)
log.Errorf("failed to read block %s: %v", blkID, err)
}
return nil
}
Expand All @@ -571,7 +571,7 @@ func doFileRange(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, f
err := blockmgr.Read(repo.StoreID, blkID, rsp)
if err != nil {
if !isNetworkErr(err) {
log.Printf("failed to read block %s: %v", blkID, err)
log.Errorf("failed to read block %s: %v", blkID, err)
}
return nil
}
Expand Down Expand Up @@ -763,7 +763,7 @@ func doBlock(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, fileI
err = blockmgr.Read(repo.StoreID, blkID, rsp)
if err != nil {
if !isNetworkErr(err) {
log.Printf("failed to read block %s: %v", blkID, err)
log.Errorf("failed to read block %s: %v", blkID, err)
}
}

Expand Down Expand Up @@ -861,7 +861,7 @@ func downloadZipFile(rsp http.ResponseWriter, r *http.Request, data, repoID, use

err := packDir(ar, repo, objID, dirName, cryptKey)
if err != nil {
log.Printf("failed to pack dir %s: %v", dirName, err)
log.Errorf("failed to pack dir %s: %v", dirName, err)
return nil
}
} else {
Expand All @@ -885,14 +885,14 @@ func downloadZipFile(rsp http.ResponseWriter, r *http.Request, data, repoID, use
if fsmgr.IsDir(v.Mode) {
if err := packDir(ar, repo, v.ID, uniqueName, cryptKey); err != nil {
if !isNetworkErr(err) {
log.Printf("failed to pack dir %s: %v", v.Name, err)
log.Errorf("failed to pack dir %s: %v", v.Name, err)
}
return nil
}
} else {
if err := packFiles(ar, &v, repo, "", uniqueName, cryptKey); err != nil {
if !isNetworkErr(err) {
log.Printf("failed to pack file %s: %v", v.Name, err)
log.Errorf("failed to pack file %s: %v", v.Name, err)
}
return nil
}
Expand Down Expand Up @@ -1230,10 +1230,7 @@ func doUpload(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo
if fsm.rend != fsm.fsize-1 {
rsp.Header().Set("Content-Type", "application/json; charset=utf-8")
success := "{\"success\": true}"
_, err := rsp.Write([]byte(success))
if err != nil {
log.Printf("failed to write data to response")
}
rsp.Write([]byte(success))

return nil
}
Expand Down Expand Up @@ -2154,23 +2151,23 @@ func notifRepoUpdate(repoID string, commitID string) error {
event.Content = content
msg, err := json.Marshal(event)
if err != nil {
log.Printf("failed to encode repo update event: %v", err)
log.Errorf("failed to encode repo update event: %v", err)
return err
}

url := fmt.Sprintf("http://%s/events", option.NotificationURL)
exp := time.Now().Add(time.Second * 300).Unix()
token, err := utils.GenNotifJWTToken(repoID, "", exp)
if err != nil {
log.Printf("failed to generate jwt token: %v", err)
log.Errorf("failed to generate jwt token: %v", err)
return err
}
header := map[string][]string{
"Authorization": {"Token " + token},
}
_, _, err = utils.HttpCommon("POST", url, header, bytes.NewReader(msg))
if err != nil {
log.Printf("failed to send repo update event: %v", err)
log.Warnf("failed to send repo update event: %v", err)
return err
}

Expand Down Expand Up @@ -2340,7 +2337,7 @@ func nameExists(entries []*fsmgr.SeafDirent, fileName string) bool {

func shouldIgnoreFile(fileName string) bool {
if !utf8.ValidString(fileName) {
log.Printf("file name %s contains non-UTF8 characters, skip", fileName)
log.Warnf("file name %s contains non-UTF8 characters, skip", fileName)
return true
}

Expand Down Expand Up @@ -2473,7 +2470,7 @@ type chunkingResult struct {
func createChunkPool(ctx context.Context, n int, chunkJobs chan chunkingData, res chan chunkingResult) {
defer func() {
if err := recover(); err != nil {
log.Printf("panic: %v\n%s", err, debug.Stack())
log.Errorf("panic: %v\n%s", err, debug.Stack())
}
}()
var wg sync.WaitGroup
Expand All @@ -2488,7 +2485,7 @@ func createChunkPool(ctx context.Context, n int, chunkJobs chan chunkingData, re
func chunkingWorker(ctx context.Context, wg *sync.WaitGroup, chunkJobs chan chunkingData, res chan chunkingResult) {
defer func() {
if err := recover(); err != nil {
log.Printf("panic: %v\n%s", err, debug.Stack())
log.Errorf("panic: %v\n%s", err, debug.Stack())
}
}()
for job := range chunkJobs {
Expand Down Expand Up @@ -3013,10 +3010,7 @@ func doUpdate(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo
if fsm.rend != fsm.fsize-1 {
rsp.Header().Set("Content-Type", "application/json; charset=utf-8")
success := "{\"success\": true}"
_, err := rsp.Write([]byte(success))
if err != nil {
log.Printf("failed to write data to response.\n")
}
rsp.Write([]byte(success))

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions fileserver/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func main() {

err = server.ListenAndServe()
if err != nil {
log.Printf("File server exiting: %v", err)
log.Errorf("File server exiting: %v", err)
}
}

Expand Down Expand Up @@ -549,7 +549,7 @@ type appHandler func(http.ResponseWriter, *http.Request) *appError
func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if e := fn(w, r); e != nil {
if e.Error != nil && e.Code == http.StatusInternalServerError {
log.Printf("path %s internal server error: %v\n", r.URL.Path, e.Error)
log.Errorf("path %s internal server error: %v\n", r.URL.Path, e.Error)
}
http.Error(w, e.Message, e.Code)
}
Expand All @@ -558,7 +558,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func RecoverWrapper(f func()) {
defer func() {
if err := recover(); err != nil {
log.Printf("panic: %v\n%s", err, debug.Stack())
log.Errorf("panic: %v\n%s", err, debug.Stack())
}
}()

Expand Down
18 changes: 9 additions & 9 deletions fileserver/repomgr/repomgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func Get(id string) *Repo {
defer cancel()
stmt, err := seafileDB.PrepareContext(ctx, query)
if err != nil {
log.Printf("failed to prepare sql : %s :%v", query, err)
log.Errorf("failed to prepare sql : %s :%v", query, err)
return nil
}
defer stmt.Close()

rows, err := stmt.QueryContext(ctx, id)
if err != nil {
log.Printf("failed to query sql : %v", err)
log.Errorf("failed to query sql : %v", err)
return nil
}
defer rows.Close()
Expand All @@ -96,15 +96,15 @@ func Get(id string) *Repo {
if rows.Next() {
err := rows.Scan(&repo.ID, &repo.HeadCommitID, &originRepoID, &path, &baseCommitID)
if err != nil {
log.Printf("failed to scan sql rows : %v", err)
log.Errorf("failed to scan sql rows : %v", err)
return nil
}
} else {
return nil
}

if repo.HeadCommitID == "" {
log.Printf("repo %s is corrupted", id)
log.Errorf("repo %s is corrupted", id)
return nil
}

Expand All @@ -126,7 +126,7 @@ func Get(id string) *Repo {

commit, err := commitmgr.Load(repo.ID, repo.HeadCommitID)
if err != nil {
log.Printf("failed to load commit %s/%s : %v", repo.ID, repo.HeadCommitID, err)
log.Errorf("failed to load commit %s/%s : %v", repo.ID, repo.HeadCommitID, err)
return nil
}

Expand Down Expand Up @@ -206,14 +206,14 @@ func GetEx(id string) *Repo {
defer cancel()
stmt, err := seafileDB.PrepareContext(ctx, query)
if err != nil {
log.Printf("failed to prepare sql : %s :%v", query, err)
log.Errorf("failed to prepare sql : %s :%v", query, err)
return nil
}
defer stmt.Close()

rows, err := stmt.QueryContext(ctx, id)
if err != nil {
log.Printf("failed to query sql : %v", err)
log.Errorf("failed to query sql : %v", err)
return nil
}
defer rows.Close()
Expand All @@ -226,7 +226,7 @@ func GetEx(id string) *Repo {
if rows.Next() {
err := rows.Scan(&repo.ID, &repo.HeadCommitID, &originRepoID, &path, &baseCommitID)
if err != nil {
log.Printf("failed to scan sql rows : %v", err)
log.Errorf("failed to scan sql rows : %v", err)
return nil
}
} else {
Expand Down Expand Up @@ -255,7 +255,7 @@ func GetEx(id string) *Repo {

commit, err := commitmgr.Load(repo.ID, repo.HeadCommitID)
if err != nil {
log.Printf("failed to load commit %s/%s : %v", repo.ID, repo.HeadCommitID, err)
log.Errorf("failed to load commit %s/%s : %v", repo.ID, repo.HeadCommitID, err)
repo.IsCorrupted = true
return nil
}
Expand Down
20 changes: 10 additions & 10 deletions fileserver/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func CheckPerm(repoID string, user string) string {
var perm string
vInfo, err := repomgr.GetVirtualRepoInfo(repoID)
if err != nil {
log.Printf("Failed to get virtual repo info by repo id %s: %v", repoID, err)
log.Errorf("Failed to get virtual repo info by repo id %s: %v", repoID, err)
}
if vInfo != nil {
perm = checkVirtualRepoPerm(repoID, vInfo.OriginRepoID, user, vInfo.Path)
Expand All @@ -56,7 +56,7 @@ func CheckPerm(repoID string, user string) string {
func checkVirtualRepoPerm(repoID, originRepoID, user, vPath string) string {
owner, err := repomgr.GetRepoOwner(originRepoID)
if err != nil {
log.Printf("Failed to get repo owner: %v", err)
log.Errorf("Failed to get repo owner: %v", err)
}
var perm string
if owner != "" && owner == user {
Expand Down Expand Up @@ -131,7 +131,7 @@ func getGroupsByUser(userName string, returnAncestors bool) ([]group, error) {
sqlStr += ")"
paths, err := getGroupPaths(sqlStr)
if err != nil {
log.Printf("Failed to get group paths: %v", err)
log.Errorf("Failed to get group paths: %v", err)
}
if paths == "" {
err := fmt.Errorf("Failed to get groups path for user %s", userName)
Expand Down Expand Up @@ -262,30 +262,30 @@ func checkInnerPubRepoPerm(repoID string) (string, error) {
func checkRepoSharePerm(repoID string, userName string) string {
owner, err := repomgr.GetRepoOwner(repoID)
if err != nil {
log.Printf("Failed to get repo owner: %v", err)
log.Errorf("Failed to get repo owner: %v", err)
}
if owner != "" && owner == userName {
perm := "rw"
return perm
}
perm, err := checkSharedRepoPerm(repoID, userName)
if err != nil {
log.Printf("Failed to get shared repo permission: %v", err)
log.Errorf("Failed to get shared repo permission: %v", err)
}
if perm != "" {
return perm
}
perm, err = checkGroupPermByUser(repoID, userName)
if err != nil {
log.Printf("Failed to get group permission by user %s: %v", userName, err)
log.Errorf("Failed to get group permission by user %s: %v", userName, err)
}
if perm != "" {
return perm
}
if !cloudMode {
perm, err = checkInnerPubRepoPerm(repoID)
if err != nil {
log.Printf("Failed to get inner pulic repo permission by repo id %s: %v", repoID, err)
log.Errorf("Failed to get inner pulic repo permission by repo id %s: %v", repoID, err)
return ""
}
return perm
Expand Down Expand Up @@ -386,7 +386,7 @@ func checkPermOnParentRepo(originRepoID, user, vPath string) string {
var perm string
userPerms, err := getSharedDirsToUser(originRepoID, user)
if err != nil {
log.Printf("Failed to get all shared folder perms in parent repo %.8s for user %s", originRepoID, user)
log.Errorf("Failed to get all shared folder perms in parent repo %.8s for user %s", originRepoID, user)
return ""
}
if len(userPerms) > 0 {
Expand All @@ -398,15 +398,15 @@ func checkPermOnParentRepo(originRepoID, user, vPath string) string {

groups, err := getGroupsByUser(user, false)
if err != nil {
log.Printf("Failed to get groups by user %s: %v", user, err)
log.Errorf("Failed to get groups by user %s: %v", user, err)
}
if len(groups) == 0 {
return perm
}

groupPerms, err := getSharedDirsToGroup(originRepoID, groups)
if err != nil {
log.Printf("Failed to get all shared folder perm from parent repo %.8s to all user groups", originRepoID)
log.Errorf("Failed to get all shared folder perm from parent repo %.8s to all user groups", originRepoID)
return ""
}
if len(groupPerms) == 0 {
Expand Down
Loading
Loading