Esempio n. 1
0
func InitializeMutipleExecutions(processid string, logfilename string) *GoLog {
	/*This is the Start Up Function That should be called right at the start of
	  a program
	*/
	gv := New() //Simply returns a new struct
	gv.pid = processid

	//# These are bools that can be changed to change debuging nature of library
	gv.printonscreen = false //(ShouldYouSeeLoggingOnScreen)
	gv.VConWire = true       // (ShouldISendVectorClockonWire)
	gv.debugmode = false     // (Debug)
	gv.EnableLogging()
	//we create a new Vector Clock with processname and 0 as the intial time
	vc1 := vclock.New()
	vc1.Update(processid, 1)

	//Vector Clock Stored in bytes
	//copy(gv.currentVC[:],vc1.Bytes())
	gv.currentVC = vc1.Bytes()

	if gv.debugmode == true {
		fmt.Println(" ###### Initialization ######")
		fmt.Print("VCLOCK IS :")
		vc1.PrintVC()
		fmt.Println(" ##### End of Initialization ")
	}

	//Starting File IO . If Log exists, it will find Last execution number and ++ it
	logname := logfilename + "-Log.txt"
	_, err := os.Stat(logname)
	gv.logfile = logname
	if err == nil {
		//its exists... deleting old log
		fmt.Println(logname, " exists! ...  Looking for Last Exectution... ")
		executionnumber := FindExecutionNumber(logname)
		executionnumber = executionnumber + 1
		fmt.Println("Execution Number is  ", executionnumber)
		executionstring := "=== Execution #" + strconv.Itoa(executionnumber) + "  ==="
		gv.LogThis(executionstring, "", "")
	} else {
		//Creating new Log
		file, err := os.Create(logname)
		if err != nil {
			panic(err)
		}
		file.Close()

		//Mark Execution Number
		ok := gv.LogThis("=== Execution #1 ===", " ", " ")
		//Log it
		ok = gv.LogThis("Initialization Complete", gv.pid, vc1.ReturnVCString())
		if ok == false {
			fmt.Println("Something went Wrong, Could not Log!")
		}
	}
	return gv
}
Esempio n. 2
0
func Initialize(processid string, logfilename string) *GoLog {
	/*This is the Start Up Function That should be called right at the start of
	  a program
	*/
	gv := New() //Simply returns a new struct
	gv.pid = processid

	//# These are bools that can be changed to change debuging nature of library
	gv.printonscreen = false //(ShouldYouSeeLoggingOnScreen)
	gv.VConWire = true       // (ShouldISendVectorClockonWire)
	gv.debugmode = false     // (Debug)
	gv.EnableLogging()
	//we create a new Vector Clock with processname and 0 as the intial time
	vc1 := vclock.New()
	vc1.Update(processid, 1)

	//Vector Clock Stored in bytes
	//copy(gv.currentVC[:],vc1.Bytes())
	gv.currentVC = vc1.Bytes()

	if gv.debugmode == true {
		fmt.Println(" ###### Initialization ######")
		fmt.Print("VCLOCK IS :")
		vc1.PrintVC()
		fmt.Println(" ##### End of Initialization ")
	}

	//Starting File IO . If Log exists, Log Will be deleted and A New one will be created
	logname := logfilename + "-Log.txt"

	if _, err := os.Stat(logname); err == nil {
		//its exists... deleting old log
		fmt.Println(logname, "exists! ... Deleting ")
		os.Remove(logname)
	}
	//Creating new Log
	file, err := os.Create(logname)
	if err != nil {
		panic(err)
	}
	file.Close()

	gv.logfile = logname
	//Log it
	ok := gv.LogThis("Initialization Complete", gv.pid, vc1.ReturnVCString())
	if ok == false {
		fmt.Println("Something went Wrong, Could not Log!")
	}

	return gv
}