Example #1
0
func TestUserModelCreate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisUser := dto.User{
		Name:  "Rate My First User",
		Email: "*****@*****.**",
		//Status:   dto.SetStatus(dto.INITIALIZED),
	}
	umodel := UserModel{}
	operation, _ := GetVDLOperation(umodel, "create")
	gotUser, retCode, err := umodel.Create(operation, &getThisUser)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	userId = (*gotUser).Id
	log.Printf("%s Successful for %#v", funcName, gotUser)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #2
0
func TestUserModelUpdate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestUserModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisUser := dto.User{
		Email:  "*****@*****.**",
		Status: dto.SetStatus(dto.ACTIVE),
	}
	umodel := UserModel{}
	operation, _ := GetVDLOperation(umodel, "update")
	user_id := int64(userId)
	gotUser, retCode, err := umodel.Update(operation, user_id, &getThisUser)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	userId = (*gotUser).Id
	log.Printf("%s Successful for %#v", funcName, gotUser)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #3
0
File: main.go Project: 205c/git
func main() {
	flag.Parse()
	if *printLabel {
		// Short circuit execution to print the build label
		fmt.Println(buildLabel())
		return
	}

	var err error
	if *forceProxy || strings.HasSuffix(os.Args[0], "--proxy") {
		log.SetPrefix("git-remote-persistent-https--proxy: ")
		proxy := &Proxy{
			BuildLabel:         buildLabel(),
			MaxIdleDuration:    defaultMaxIdleDuration,
			PollUpdateInterval: defaultPollUpdateInterval,
		}
		err = proxy.Run()
	} else {
		log.SetPrefix("git-remote-persistent-https: ")
		client := &Client{
			ProxyBin: *proxyBin,
			Args:     flag.Args(),
		}
		err = client.Run()
	}
	if err != nil {
		log.Fatalln(err)
	}
}
Example #4
0
func TestMicroPageSvcDeletePage(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + ":")
	mps.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/page")
	//mps.MicroSvc.AddModel(mockmodel.MockPageModel{})
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "DeletePage",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2",
			Sub: map[string]string{
				"%1": mps.MicroSvc.GetFullPath(),
				"%2": "3",
			},
			Method:          "DELETE",
			Status:          http.StatusOK,
			PreAuthId:       7,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
	}
	//mod, _ := mps.MicroSvc.getModel(mps.MicroSvc.GetFullPath())
	//log.Println("----------------------------------------------------------------------------")
	//log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	//log.Println("----------------------------------------------------------------------------")
	//resttest.RunTestSet(t, tests)
	// Test w/Actual database
	mps.MicroSvc.AddModel(model.PageModel{})
	mod, _ := mps.MicroSvc.getModel(mps.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	log.SetPrefix("")
}
Example #5
0
// SetPrefix delegates to standard log package SetPrefix and adds "[ ]" around the prefix
func SetPrefix(s string) {
	if s != "" {
		log.SetPrefix("[" + s + "] ")
	} else {
		log.SetPrefix("")
	}
}
Example #6
0
func TestUserModelDelete(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestUserModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	umodel := UserModel{}
	operation, _ := GetVDLOperation(umodel, "delete")
	user_id := int64(userId)
	gotUser, retCode, err := umodel.Delete(operation, user_id)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	userId = (*gotUser).Id
	log.Printf("%s Successful for %#v", funcName, gotUser)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #7
0
func TestTagModelUpdateStatus(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestTagModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	smodel := TagModel{}
	operation, _ := GetVDLOperation(smodel, "updatestatus")
	tag_id := int64(tagId)
	gotTag, retCode, err := smodel.UpdateStatus(operation, tag_id, dto.BANNED)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	tagId = (*gotTag).Id
	log.Printf("%s Successful for %#v", funcName, gotTag)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #8
0
func TestSectionModelUpdate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestSectionModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisSection := dto.Section{
		Name:     "Update My First Section",
		PageId:   pageId,
		OrderNum: 1,
		Status:   dto.SetStatus(dto.ACTIVE),
	}
	smodel := SectionModel{}
	operation, _ := GetVDLOperation(smodel, "update")
	section_id := int64(sectionId)
	gotSection, retCode, err := smodel.Update(operation, section_id, &getThisSection)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	sectionId = (*gotSection).Id
	log.Printf("%s Successful for %#v", funcName, gotSection)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #9
0
func logMsg(level string, L *lua.LState) int {
	old := log.Prefix()
	log.SetPrefix(level)
	tpl := L.CheckString(1)
	top := L.GetTop()

	// Optimization for the case where no formatter needs to be
	// applied.
	if top <= 1 {
		log.Print(tpl)
		log.SetPrefix(old)
		return 0
	}

	args := make([]interface{}, top-1)
	for i := 2; i <= top; i++ {
		args[i-2] = L.Get(i)
	}

	// FIXME: If more args are supplied than placeholders, this will
	// generate an error.
	log.Printf(tpl, args...)
	log.SetPrefix(old)
	return 0
}
Example #10
0
func TestTagModelFindById(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestTagModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	smodel := TagModel{}
	operation, _ := GetVDLOperation(smodel, "findbyid")
	tag_id := int64(tagId)
	gotSection, retCode, err := smodel.FindById(operation, tag_id)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	sectionId = (*gotSection).Id
	log.Printf("%s Successful for %#v", funcName, gotSection)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #11
0
// Start the worker by starting a goroutine, that is an infinite "for-select" loop
func (w *Worker) Start() {
	runtime.SetFinalizer(w, finalizer)
	receivedQuitSignal := false

	go func() {
		for {
			if receivedQuitSignal == false {
				// Add ourselves into the worker queue if not going to stop
				w.WorkerQueue <- w.Work
			}

			select {
			case work := <-w.Work:
				// Receive a work request
				log.SetPrefix("[Worker " + strconv.Itoa(w.ID) + "] ")
				log.Printf("Received work request")

				w.Handler(w, work)

				if receivedQuitSignal != false {
					log.SetPrefix("[Worker " + strconv.Itoa(w.ID) + "] ")
					log.Printf("Terminating\n")
					return
				}
			case <-w.QuitChan:
				// Flag the worker to stop after next request
				// This is in order to remove the worker itself from WorkerQueue
				log.SetPrefix("[Worker " + strconv.Itoa(w.ID) + "] ")
				log.Printf("Going to stop after processing another work request\n")
				receivedQuitSignal = true
			}
		}
	}()
}
Example #12
0
func TestRevisionModelCreate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("---------------- Starting  Test ( %s )---------------------", funcName)
	TestUserModelCreate(t)
	TestSectionModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisRevision := dto.Revision{
		SectionId: sectionId,
		Content:   "Content for my first revision <b>has tags</b>",
	}
	smodel := RevisionModel{}
	if gotRevision, retCode, err := smodel.Create("create_revision", userId, &getThisRevision); gotRevision == nil || err != nil {
		//if gotRevision == nil || err != nil {
		log.Fatalf(" RevisionModel Create Failed: %#v", err)
		count.FailCount++
		return
	} else {

		if got, want := retCode, 0; got != want {
			t.Errorf("RevisionModelCreate Broken: got  %d, wanted  %d", got, want)
			count.FailCount++
			return
		}
		revId = (*gotRevision).Id
		log.Printf("RevisionModel Create Successful for %#v", gotRevision)
		count.SuccessCount++
	}
	log.SetPrefix("")
}
Example #13
0
func TestMicroRevisionSvcCreateTagRelationship(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	mrs.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/revision")
	mrs.MicroSvc.AddModel(model.RevisionModel{})
	mrs.MicroSvc.AddRelationship(reflect.TypeOf(dto.Tag{}), mockmodel.MockEntityRelationshipModel{})
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "CreateTagRelationship",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2/tag/%3",
			Sub: map[string]string{
				"%1": mrs.MicroSvc.GetFullPath(),
				"%2": "1",
				"%3": "1",
			},
			Method:          "PUT",
			Status:          http.StatusOK,
			PreAuthId:       7,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
	}
	mod, _ := mrs.MicroSvc.getModel(mrs.MicroSvc.GetFullPath())
	rel := mrs.MicroSvc.getRelationship(reflect.TypeOf(dto.Tag{}))
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Printf("----- Testing with Relationship ( %s )---------------------", reflect.TypeOf(rel))
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	//// Test w/Actual database
	log.SetPrefix("")
}
Example #14
0
func TestTagModelCreate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisTag := dto.Tag{
		Name:        "test tag",
		Description: "Content for my first tag <b>has tags</b>",
		Status:      dto.SetStatus(dto.INITIALIZED),
	}
	smodel := TagModel{}
	operation, _ := GetVDLOperation(smodel, "create")
	gotTag, retCode, err := smodel.Create(operation, &getThisTag)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	tagId = (*gotTag).Id
	log.Printf("%s Successful for %#v", funcName, gotTag)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #15
0
func TestPageModelCreate(t *testing.T) {
	log.Printf("---------------- Starting  Test ( %s )---------------------", util.GetCallerName())
	TestUserModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisPage := dto.Page{
		Title: "Rate My First Page",
	}
	pmodel := PageModel{}
	operation, _ := GetVDLOperation(pmodel, "create")
	author_id := int64(userId)
	gotPage, retCode, err := pmodel.Create(operation, author_id, &getThisPage)
	if err != nil {
		log.Fatalf(" PageModel Create Failed: %#v", err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("PageModelCreate Broken: got  %d, wanted  %d", got, want)
		count.FailCount++
		return
	}
	pageId = (*gotPage).Id
	log.Printf("PageModel Create Successful for %#v", gotPage)
	count.SuccessCount++
	log.SetPrefix("")
}
Example #16
0
func TestRevisionModelUpdate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("---------------- Starting  Test ( %s )---------------------", funcName)
	TestRevisionModelCreate(t)
	log.SetPrefix(funcName + " : ")
	getThisRevision := dto.Revision{
		Id:      revId,
		Content: "Content for my first revision <b>has tags</b>",
		Status:  dto.SetStatus(dto.INITIALIZED),
	}
	smodel := RevisionModel{}
	if gotRevision, retCode, err := smodel.Update("update_revision", revId, &getThisRevision); gotRevision == nil || err != nil {
		//if gotRevision == nil || err != nil {
		log.Fatalf(" %s Failed: %#v", funcName, err)
		count.FailCount++
		return
	} else {

		if got, want := retCode, 0; got != want {
			t.Errorf("%s Broken: got  %d, wanted  %d", funcName, got, want)
			count.FailCount++
			return
		}
		revId = (*gotRevision).Id
		log.Printf("%s Successful for %#v", funcName, gotRevision)
		count.SuccessCount++
	}
	log.SetPrefix("")
}
Example #17
0
// Logf logs a message to one or more loggers and uses a format string.
func (cxt *ExecutionContext) Logf(prefix string, format string, v ...interface{}) {
	if _, ok := cxt.skiplist[prefix]; ok {
		return
	}
	tmpPrefix := log.Prefix()
	log.SetPrefix(prefix)
	log.Printf(format, v...)
	log.SetPrefix(tmpPrefix)
}
Example #18
0
File: log.go Project: sknop/direnv
func logMsg(format, msg string, a ...interface{}) {
	defer log.SetFlags(log.Flags())
	defer log.SetPrefix(log.Prefix())
	log.SetFlags(0)
	log.SetPrefix("")

	msg = fmt.Sprintf(format+"\n", msg)
	log.Printf(msg, a...)
}
Example #19
0
File: log.go Project: sknop/direnv
func setupLogging(env Env) {
	log.SetFlags(0)
	log.SetPrefix("")
	if val, ok := env[DIRENV_DEBUG]; ok == true && val == "1" {
		debugging = true
		log.SetFlags(log.Ltime)
		log.SetPrefix("direnv: ")
	}
}
Example #20
0
// Start dispatcher for the given manager with nworkers as the initial number of
// workers
func (d *Dispatcher) Start(nworkers int, workerHandler func(worker *Worker, work WorkRequest)) {
	d.workerHandler = workerHandler
	d.nbRequests = 0
	d.workers = make(map[int]*Worker)
	d.WorkQueue = make(chan WorkRequest, 10000)
	d.WorkerQueue = make(chan chan WorkRequest, 10000)

	tickerCheck := time.NewTicker(5 * time.Second)

	// Now, create all of our workers.
	for i := 0; i < nworkers; i++ {
		d.createWorker(i+1, d.WorkerQueue)
	}

	go func() {
		for {
			select {
			case <-tickerCheck.C:
				go func() {
					counter := len(d.WorkQueue)
					log.SetPrefix("[Dispatcher] ")
					log.Printf(
						"nbWorkerQueue - nbWorkQueue - nbWorkers: %v - %v - %v",
						len(d.WorkerQueue), counter, len(d.workers),
					)

					if counter > 10 {
						// A simple mechanism of auto-spawning
						workersToCreate := int(math.Ceil(float64(counter / 10)))
						log.SetPrefix("[Dispatcher] ")
						log.Printf("Going to add %v workers", workersToCreate)
						for i := 0; i < workersToCreate; i++ {
							d.createWorker(len(d.workers)+1, d.WorkerQueue)
						}
					} else if counter < 5 && len(d.workers) > nworkers {
						// Stop 2 workers a time but do not drop below the initial number of workers
						d.removeWorker(len(d.workers))
						if len(d.workers) > nworkers {
							d.removeWorker(len(d.workers))
						}
					}
				}()
			case work := <-d.WorkQueue:
				// Blocking process here, in order to benefit the buffered channel
				// Count the requests received
				d.nbRequests++
				log.SetPrefix("[Dispatcher] ")
				log.Println("Received work request")
				worker := <-d.WorkerQueue
				worker <- work
			}
		}
	}()
}
Example #21
0
// Print calls Print only if the level is equal or lower than the set level.
// If the level is FatalLevel, it will call Fatal regardless...
func Print(l Level, v ...interface{}) {
	if l == FatalLevel {
		stdLog.Fatal(v...)
		return
	}

	if l <= level {
		defer stdLog.SetPrefix(stdLog.Prefix())
		stdLog.SetPrefix(levelPrefix[l])
		stdLog.Print(v...)
	}
}
Example #22
0
// Printf calls Printf only if the level is equal or lower than the set level.
// If the level is FatalLevel, it will call Fatalf regardless...
func Printf(l Level, format string, v ...interface{}) {
	if l == FatalLevel {
		stdLog.Fatalf(format, v...)
		return
	}

	if l <= level {
		defer stdLog.SetPrefix(stdLog.Prefix())
		stdLog.SetPrefix(levelPrefix[l])
		stdLog.Printf(format, v...)
	}
}
Example #23
0
// parse flags, setup logging and then launch server
func main() {
	// flag variables
	var (
		stderr, errPrefix bool
		addr, logPath     string
	)
	// declare and parse flags
	flag.BoolVar(&stderr, "e", false, "stderr logging")
	flag.BoolVar(&errPrefix, "t", false, "stderr logging prefix (name, timestamp)")
	flag.StringVar(&addr, "l", "", "listening address; ip:port")
	flag.StringVar(&logPath, "p", "", "path to logfile")
	flag.Parse()
	// setup logging based on flags
	logger = &fileLogger{stderr: stderr}
	if errPrefix == false {
		log.SetFlags(0)
		log.SetPrefix("")
	} else {
		log.SetPrefix("cserver: ")
	}
	go func() {
		sigs := make(chan os.Signal, 1)
		signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
		logger.println("got signal", <-sigs)
		logger.println("exiting")
		os.Exit(0)
	}()
	if logPath != "" {
		logFile, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			log.Fatal(err)
		}
		logger.Logger = log.New(logFile, "cserver: ", 3)
	}
	// fix listen address if just port and begin listening
	if !strings.Contains(addr, ":") {
		addr = ":" + addr
	}
	s := &server{
		addUname:    make(chan *client),
		remUname:    make(chan *client),
		addToChan:   make(chan *client),
		remFromChan: make(chan *client),
		rmChan:      make(chan bool),
		msgUser:     make(chan message),
	}
	log.Fatal(s.listenAndServe(addr))
}
Example #24
0
// Program launched. Create and activate applet.
//
func main() {
	app := Update()

	log.SetPrefix(term.Yellow("[" + app.AppletName + "] "))
	log.Println(term.Green("Applet started"))
	defer log.Println(term.Yellow("Applet stopped"))

	// Start main loop and wait for events. Until the End signal is received from the dock.
	ticker, restart := app.poller.NewTicker()
	for { // Main loop, waiting for events.
		select {
		case <-app.Close: // That's all folks.
			return

		// not triggered yet.
		case <-restart: // Want to recheck now ?
			log.Println(term.Yellow("timer restart"))
			ticker, restart = app.poller.NewTicker()

		case <-ticker.C: // It's time to work !
			//~ log.Println(term.Yellow("timer"))
			app.poller.Check()
		}
	}
}
Example #25
0
func init() {
	hooks = hook.Hooks{}

	flag.Parse()

	log.SetPrefix("[webhook] ")
	log.SetFlags(log.Ldate | log.Ltime)

	if !*verbose {
		log.SetOutput(ioutil.Discard)
	}

	log.Println("version " + version + " starting")

	// load and parse hooks
	log.Printf("attempting to load hooks from %s\n", *hooksFilePath)

	err := hooks.LoadFromFile(*hooksFilePath)

	if err != nil {
		if !*verbose && !*noPanic {
			log.SetOutput(os.Stdout)
			log.Fatalf("couldn't load any hooks from file! %+v\naborting webhook execution since the -verbose flag is set to false.\nIf, for some reason, you want webhook to start without the hooks, either use -verbose flag, or -nopanic", err)
		}

		log.Printf("couldn't load hooks from file! %+v\n", err)
	} else {
		log.Printf("loaded %d hook(s) from file\n", len(hooks))

		for _, hook := range hooks {
			log.Printf("\t> %s\n", hook.ID)
		}
	}
}
Example #26
0
func main() {
	log.SetPrefix("gounexport: ")
	err := do(os.Stdout, flag.CommandLine, os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}
}
Example #27
0
// setupLogging attempts to log to a file, otherwise stderr
func setupLogging() (*os.File, error) {
	// use date, time and filename for log output
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	log.SetPrefix(*pluginName + "-volume-plugin: ")

	// setup logfile - path is set from logfileDir and pluginName
	logfileName := logfilePath()
	if !isDebugEnabled() && logfileName != "" {
		logFile, err := os.OpenFile(logfileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
		if err != nil {
			// check if we can write to directory - otherwise just log to stderr?
			if os.IsPermission(err) {
				log.Printf("WARN: logging fallback to STDERR: %v", err)
			} else {
				// some other, more extreme system error
				return nil, err
			}
		} else {
			log.Printf("INFO: setting log file: %s", logfileName)
			log.SetOutput(logFile)
			return logFile, nil
		}
	}
	return nil, nil
}
Example #28
0
func init() {
	pkg := NewPackageLogger("log", "")
	w := packageWriter{pkg}
	log.SetFlags(0)
	log.SetPrefix("")
	log.SetOutput(w)
}
Example #29
0
func init() {
	//assign flags
	flag.IntVar(&size, "size", 1000, "usage: -size 1000")
	flag.IntVar(&length, "length", 100000, "usage: -length 1000")
	flag.IntVar(&etime, "time", 1000, "usage: -time 1000")
	flag.IntVar(&sampleSize, "samplesize", 100, "usage: -samplesize 1000")
	flag.IntVar(&stepSize, "stepsize", 1000, "usage: -stepsize 1000")
	flag.IntVar(&maxL, "maxl", 1000, "usage: -maxl 1000")
	flag.IntVar(&fragment, "fragment", 1000, "usage: -fragment 1000")
	flag.Float64Var(&mutationRate, "mutation", 1, "usage: -mutation 1e-8")
	flag.Float64Var(&transferRate, "transfer", 0, "usage: -transfer 1e-9")
	flag.StringVar(&prex, "prex", "default", "usage: -prex default")
	flag.StringVar(&dir, "out", "out", "usage: -dir out")

	// parse flags
	flag.Parse()
	log.SetPrefix(prex + ":")

	// get start time
	tnow = time.Now()
	log.Printf("Begin at %v\n", tnow.Format("Mon Jan 2 15:04:05"))

	// init population
	pop = fwd.NewSeqPopulation(size, length, fragment, mutationRate, transferRate)
	//log.Println("Population: ", pop)
	log.Println("Population initialized.")

	// determine how many cpus that we can use
	ncpu := runtime.NumCPU()
	runtime.GOMAXPROCS(ncpu)
	log.Println("Number of CPU used: ", ncpu)
}
Example #30
0
File: goxc.go Project: relops/goxc
func main() {
	log.SetPrefix("[goxc] ")
	err := goXC(os.Args)
	if err != nil {
		os.Exit(1)
	}
}