adding logging to server
This commit is contained in:
		@@ -16,14 +16,14 @@ func (db *DB) ConfigureDB(dbPath string) error {
 | 
			
		||||
	var file File
 | 
			
		||||
	if err := db.One("Name", "-- All Files --", &file); err != nil {
 | 
			
		||||
		if err.Error() != "not found" {
 | 
			
		||||
			db.ErrorF("Error finding file by path %s", err)
 | 
			
		||||
			db.Err(err).Msg("Error finding file by path")
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		db.WarningF("No existing databse found. initialising new database")
 | 
			
		||||
		db.Warn().Msg("No existing databse found. initialising new database")
 | 
			
		||||
		file.Name = "-- All Files --"
 | 
			
		||||
		//file.Ignore = true //this is currently not used however could result in this file being ignored when file watching (etc) starts
 | 
			
		||||
		if err := db.Save(&file); err != nil {
 | 
			
		||||
			db.ErrorF("Error storing the diff %s", err)
 | 
			
		||||
			db.Err(err).Msg("Error storing the diff")
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -39,14 +39,13 @@ func (db *DB) CheckIfFileCurrentlyMonitored(src string, hash [16]byte) (File, er
 | 
			
		||||
	//TODO: check this actually works still (don't need hash passed to this anymore)
 | 
			
		||||
	if err := db.One("Path", src, &file); err != nil {
 | 
			
		||||
		if err.Error() != "not found" {
 | 
			
		||||
			db.ErrorF("Error finding file by path %s", err)
 | 
			
		||||
			db.Err(err).Msg("Error finding file by path")
 | 
			
		||||
			return File{}, err
 | 
			
		||||
		}
 | 
			
		||||
		db.WarningF("no file found, %s", err)
 | 
			
		||||
		db.Warn().Msg("no file found")
 | 
			
		||||
		return File{}, err
 | 
			
		||||
	} else {
 | 
			
		||||
		return file, nil
 | 
			
		||||
	}
 | 
			
		||||
	return file, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RetrieveWatchedFiles all files that are in the database as "watched files"
 | 
			
		||||
@@ -54,11 +53,10 @@ func (db *DB) CheckIfFileCurrentlyMonitored(src string, hash [16]byte) (File, er
 | 
			
		||||
func (db *DB) RetrieveWatchedFiles() ([]File, error) {
 | 
			
		||||
	var files []File
 | 
			
		||||
	if err := db.All(&files); err != nil {
 | 
			
		||||
		db.ErrorF("Error retrieving all watched files %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error retrieving all watched files")
 | 
			
		||||
		return []File{}, err
 | 
			
		||||
	} else {
 | 
			
		||||
		return files, nil
 | 
			
		||||
	}
 | 
			
		||||
	return files, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RetrieveAllDiffs retrieves all files that are in the database as "watched files"
 | 
			
		||||
@@ -66,7 +64,7 @@ func (db *DB) RetrieveWatchedFiles() ([]File, error) {
 | 
			
		||||
// func (db *DB) RetrieveAllDiffs() ([]DiffObject, error) {
 | 
			
		||||
// 	var diffs []DiffObject
 | 
			
		||||
// 	if err := db.All(&diffs); err != nil {
 | 
			
		||||
// 		db.ErrorF("Error retrieving all diffs %s", err)
 | 
			
		||||
// 		db.Err(err).Msg("Error retrieving all diffs ")
 | 
			
		||||
// 		return []DiffObject{}, err
 | 
			
		||||
// 	} else {
 | 
			
		||||
// 		return diffs, nil
 | 
			
		||||
@@ -78,7 +76,7 @@ func (db *DB) RetrieveWatchedFiles() ([]File, error) {
 | 
			
		||||
// of losing references
 | 
			
		||||
func (db *DB) InitialiseFileInDatabase(file File) (int, error) {
 | 
			
		||||
	if err := db.Save(&file); err != nil {
 | 
			
		||||
		db.ErrorF("Error initialising file in database %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error initialising file in database")
 | 
			
		||||
		return file.ID, err
 | 
			
		||||
	}
 | 
			
		||||
	return file.ID, nil
 | 
			
		||||
@@ -88,7 +86,7 @@ func (db *DB) InitialiseFileInDatabase(file File) (int, error) {
 | 
			
		||||
func (db *DB) FindFileByPath(filePath string) (File, error) {
 | 
			
		||||
	var file File
 | 
			
		||||
	if err := db.One("Path", filePath, &file); err != nil {
 | 
			
		||||
		db.ErrorF("Error finding file by path %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error finding file by path")
 | 
			
		||||
		return File{}, err
 | 
			
		||||
	}
 | 
			
		||||
	return file, nil
 | 
			
		||||
@@ -98,7 +96,7 @@ func (db *DB) FindFileByPath(filePath string) (File, error) {
 | 
			
		||||
func (db *DB) FindFileByID(ID int) (File, error) {
 | 
			
		||||
	var file File
 | 
			
		||||
	if err := db.One("ID", ID, &file); err != nil {
 | 
			
		||||
		db.ErrorF("Error finding file by path %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error finding file by path")
 | 
			
		||||
		return File{}, err
 | 
			
		||||
	}
 | 
			
		||||
	return file, nil
 | 
			
		||||
@@ -107,7 +105,7 @@ func (db *DB) FindFileByID(ID int) (File, error) {
 | 
			
		||||
// UpdateFileData updates the current base file that diffs will compare to
 | 
			
		||||
func (db *DB) UpdateFileData(filePath, basePath string, hash [16]byte) error {
 | 
			
		||||
	if file, err := db.FindFileByPath(filePath); err != nil {
 | 
			
		||||
		db.ErrorF("Error updating the file base %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error updating the file base")
 | 
			
		||||
		return err
 | 
			
		||||
	} else {
 | 
			
		||||
		err := db.Update(&File{ID: file.ID, CurrentBase: basePath, CurrentHash: hash})
 | 
			
		||||
@@ -137,11 +135,11 @@ func (db *DB) RetrieveDiffsForFileByPath(filePath string) ([]DiffObject, error)
 | 
			
		||||
	var objDiffs []DiffObject
 | 
			
		||||
	var subDiffs []DiffObject
 | 
			
		||||
	if err := db.Find("Object", filePath, &objDiffs); err != nil && err.Error() != "not found" {
 | 
			
		||||
		db.ErrorF("Error finding diff by object %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error finding diff by object")
 | 
			
		||||
		return []DiffObject{}, err
 | 
			
		||||
	}
 | 
			
		||||
	if err := db.Find("Subject", filePath, &subDiffs); err != nil && err.Error() != "not found" {
 | 
			
		||||
		db.ErrorF("Error finding diff by subject %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error finding diff by subject")
 | 
			
		||||
		return []DiffObject{}, err
 | 
			
		||||
	}
 | 
			
		||||
	return append(objDiffs, subDiffs...), nil
 | 
			
		||||
@@ -152,7 +150,7 @@ func (db *DB) RetrieveDiffsForFileByPath(filePath string) ([]DiffObject, error)
 | 
			
		||||
// TODO: decide what to do with diffs in memory
 | 
			
		||||
// func (db *DB) StoreDiff(diff DiffObject) error {
 | 
			
		||||
// 	if err := db.Save(&diff); err != nil {
 | 
			
		||||
// 		db.ErrorF("Error storing the diff %s", err)
 | 
			
		||||
// 		db.Err(err).Msg("Error storing the diff")
 | 
			
		||||
// 		return err
 | 
			
		||||
// 	}
 | 
			
		||||
// 	return nil
 | 
			
		||||
@@ -162,7 +160,7 @@ func (db *DB) RetrieveDiffsForFileByPath(filePath string) ([]DiffObject, error)
 | 
			
		||||
func (db *DB) FindDiffByPath(patchPath string) (DiffObject, error) {
 | 
			
		||||
	var diff DiffObject
 | 
			
		||||
	if err := db.One("DiffPath", patchPath, &diff); err != nil {
 | 
			
		||||
		db.ErrorF("Error finding diff by path %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error finding diff by path")
 | 
			
		||||
		return DiffObject{}, err
 | 
			
		||||
	}
 | 
			
		||||
	return diff, nil
 | 
			
		||||
@@ -172,7 +170,7 @@ func (db *DB) FindDiffByPath(patchPath string) (DiffObject, error) {
 | 
			
		||||
func (db *DB) RetrieveDiffsByID(ID int) (DiffObject, error) {
 | 
			
		||||
	var diff DiffObject
 | 
			
		||||
	if err := db.One("ID", ID, &diff); err != nil {
 | 
			
		||||
		db.ErrorF("Error finding diff by ID %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error finding diff by ID")
 | 
			
		||||
		return DiffObject{}, err
 | 
			
		||||
	}
 | 
			
		||||
	return diff, nil
 | 
			
		||||
@@ -182,7 +180,7 @@ func (db *DB) RetrieveDiffsByID(ID int) (DiffObject, error) {
 | 
			
		||||
func (db *DB) UpdateDescription(patchID int, description string) error {
 | 
			
		||||
	fmt.Println("attempting to path with id ", patchID, " description ", description)
 | 
			
		||||
	if err := db.Update(&DiffObject{ID: patchID, Description: description}); err != nil {
 | 
			
		||||
		db.ErrorF("Error changing diff label %s", err)
 | 
			
		||||
		db.Err(err).Msg("Error changing diff label")
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user