Esempio n. 1
0
func NewLogger(uri string) (logging.Logger, errors.Error) {
	var logger logging.Logger
	if strings.HasPrefix(uri, "golog") {
		logger = logger_golog.NewLogger(os.Stderr, logging.Info, false)
		logging.SetLogger(logger)
		return logger, nil
	}
	return nil, errors.NewAdminInvalidURL("Logger", uri)
}
Esempio n. 2
0
func TestStub(t *testing.T) {
	logger := NewLogger(os.Stdout, logging.Debug, false)
	logging.SetLogger(logger)

	logger.Infof("This is a message from %s", "test")
	logging.Infof("This is a message from %s", "test")
	logger.Infop("This is a message from ", logging.Pair{"name", "test"}, logging.Pair{"Queue Size", 10}, logging.Pair{"Debug Mode", false})
	logging.Infop("This is a message from ", logging.Pair{"name", "test"})

	logger.Infom("This is a message from ", logging.Map{"name": "test", "Queue Size": 10, "Debug Mode": false})
	logging.Infom("This is a message from ", logging.Map{"name": "test"})

	logger.Requestf(logging.Warn, "This is a Request from %s", "test")
	logging.Requestf(logging.Info, "This is a Request from %s", "test")
	logger.Requestp(logging.Debug, "This is a Request from ", logging.Pair{"name", "test"})
	logging.Requestp(logging.Error, "This is a Request from ", logging.Pair{"name", "test"})

	logger.SetLevel(logging.Warn)
	fmt.Printf("Log level is %s\n", logger.Level())

	logger.Requestf(logging.Warn, "This is a Request from %s", "test")
	logging.Requestf(logging.Info, "This is a Request from %s", "test")
	logger.Requestp(logging.Debug, "This is a Request from ", logging.Pair{"name", "test"})
	logging.Requestp(logging.Error, "This is a Request from ", logging.Pair{"name", "test"})

	logger.Warnf("This is a message from %s", "test")
	logging.Infof("This is a message from %s", "test")
	logger.Debugp("This is a message from ", logging.Pair{"name", "test"})
	logging.Errorp("This is a message from ", logging.Pair{"name", "test"})

	fmt.Printf("Changing to json formatter\n")
	logger.entryFormatter = &jsonFormatter{}
	logger.SetLevel(logging.Debug)

	logger.Infof("This is a message from %s", "test")
	logging.Infof("This is a message from %s", "test")
	logger.Infop("This is a message from ", logging.Pair{"name", "test"}, logging.Pair{"Queue Size", 10}, logging.Pair{"Debug Mode", false})
	logging.Infop("This is a message from ", logging.Pair{"name", "test"})

	logger.Infom("This is a message from ", logging.Map{"name": "test", "Queue Size": 10, "Debug Mode": false})
	logging.Infom("This is a message from ", logging.Map{"name": "test"})

	logger.Requestf(logging.Warn, "This is a Request from %s", "test")
	logging.Requestf(logging.Info, "This is a Request from %s", "test")
	logger.Requestp(logging.Debug, "This is a Request from ", logging.Pair{"name", "test"})
	logging.Requestp(logging.Error, "This is a Request from ", logging.Pair{"name", "test"})
}
Esempio n. 3
0
func main() {
	flag.Parse()

	var f *os.File
	if *MEM_PROFILE != "" {
		var err error
		f, err = os.Create(*MEM_PROFILE)
		if err != nil {
			fmt.Printf("Cannot start mem profiler %v\n", err)
		}
	}

	if *CPU_PROFILE != "" {
		f, err := os.Create(*CPU_PROFILE)
		if err != nil {
			fmt.Printf("Cannot start cpu profiler %v\n", err)
		} else {
			pprof.StartCPUProfile(f)
		}
	}

	if *LOGGER != "" {
		logger, _ := log_resolver.NewLogger(*LOGGER)
		if logger == nil {
			fmt.Printf("Invalid logger: %s\n", *LOGGER)
			os.Exit(1)
		}

		logging.SetLogger(logger)
	}

	if *DEBUG {
		logging.SetLevel(logging.Debug)
		logging.Debugp("Debug mode enabled")
	} else {
		logging.SetLevel(logging.Info)
	}

	datastore, err := resolver.NewDatastore(*DATASTORE)
	if err != nil {
		logging.Errorp(err.Error())
		os.Exit(1)
	}
	datastore_package.SetDatastore(datastore)

	configstore, err := config_resolver.NewConfigstore(*CONFIGSTORE)
	if err != nil {
		logging.Errorp("Could not connect to configstore",
			logging.Pair{"error", err},
		)
	}
	acctstore, err := acct_resolver.NewAcctstore(*ACCTSTORE)
	if err != nil {
		logging.Errorp("Could not connect to acctstore",
			logging.Pair{"error", err},
		)
	} else {
		// Create the metrics we are interested in
		accounting.RegisterMetrics(acctstore)
		// Make metrics available
		acctstore.MetricReporter().Start(1, 1)
	}

	keep_alive_length, e := util.ParseQuantity(*KEEP_ALIVE_LENGTH)

	if e != nil {
		logging.Errorp("Error parsing keep alive length; reverting to default",
			logging.Pair{"keep alive length", *KEEP_ALIVE_LENGTH},
			logging.Pair{"error", e},
			logging.Pair{"default", server.KEEP_ALIVE_DEFAULT},
		)
	}

	if e == nil && keep_alive_length < 1 {
		logging.Infop("Negative or zero keep alive length; reverting to default",
			logging.Pair{"keep alive length", *KEEP_ALIVE_LENGTH},
			logging.Pair{"default", server.KEEP_ALIVE_DEFAULT},
		)
	}

	channel := make(server.RequestChannel, *REQUEST_CAP)
	server, err := server.NewServer(datastore, configstore, acctstore, *NAMESPACE, *READONLY, channel,
		*THREAD_COUNT, *TIMEOUT, *SIGNATURE, *METRICS, keep_alive_length)
	if err != nil {
		logging.Errorp(err.Error())
		os.Exit(1)
	}

	go server.Serve()

	logging.Infop("cbq-engine started",
		logging.Pair{"version", VERSION},
		logging.Pair{"datastore", *DATASTORE},
	)
	// Create http endpoint
	endpoint := http.NewServiceEndpoint(server, *STATIC_PATH, *METRICS)
	er := endpoint.Listen(*HTTP_ADDR)
	if er != nil {
		logging.Errorp("cbq-engine exiting with error",
			logging.Pair{"error", er},
			logging.Pair{"HTTP_ADDR", *HTTP_ADDR},
		)
		os.Exit(1)
	}
	if *CERT_FILE != "" && *KEY_FILE != "" {
		er := endpoint.ListenTLS(*HTTPS_ADDR, *CERT_FILE, *KEY_FILE)
		if er != nil {
			logging.Errorp("cbq-engine exiting with error",
				logging.Pair{"error", er},
				logging.Pair{"HTTP_ADDR", *HTTP_ADDR},
			)
			os.Exit(1)
		}
	}
	signalCatcher(server, endpoint, *CPU_PROFILE != "", f)
}
Esempio n. 4
0
func TestServer(t *testing.T) {

	logger, _ := log_resolver.NewLogger("golog")
	if logger == nil {
		t.Fatalf("Invalid logger")
	}

	logging.SetLogger(logger)

	site, err := NewDatastore(TEST_URL)
	if err != nil {
		t.Skipf("SKIPPING TEST: %v", err)
	}

	namespaceNames, err := site.NamespaceNames()
	if err != nil {
		t.Fatalf("Failed to get Namespace names . error %v", err)
	}

	fmt.Printf("Namespaces in this instance %v", namespaceNames)

	namespace, err := site.NamespaceByName("default")
	if err != nil {
		t.Fatalf("Namespace default not found, error %v", err)
	}

	keyspaceNames, err := namespace.KeyspaceNames()
	if err != nil {
		t.Fatalf(" Cannot fetch keyspaces names. error %v", err)
	}

	fmt.Printf("Keyspaces in this namespace %v", keyspaceNames)

	//connect to beer-sample
	ks, err := namespace.KeyspaceByName("beer-sample")
	if err != nil {
		t.Fatalf(" Cannot connect to beer-sample. Error %v", err)
		return
	}

	indexer, err := ks.Indexer(datastore.VIEW)
	if err != nil {
		fmt.Printf("No indexers found")
		return
	}

	// try create a primary index
	index, err := indexer.CreatePrimaryIndex("#primary", nil)
	if err != nil {
		// keep going. maybe index already exists
		fmt.Printf(" Cannot create a primary index on bucket. Error %v", err)
	} else {

		fmt.Printf("primary index created %v", index)
	}

	pair, err := ks.Fetch([]string{"357", "aass_brewery"})
	if err != nil {
		t.Fatalf(" Cannot fetch keys error %v", err)

	}

	fmt.Printf("Keys fetched %v", pair)
	insertKey := datastore.Pair{Key: "testBeerKey", Value: value.NewValue(("This is a random test key-value"))}

	_, err = ks.Insert([]datastore.Pair{insertKey})
	if err != nil {
		t.Fatalf("Cannot insert key %v", insertKey)
	}

	deleted, err := ks.Delete([]string{insertKey.Key})
	if err != nil || (len(deleted) != 1 && deleted[0] != insertKey.Key) {
		t.Fatalf("Failed to delete %v", err)
	}

	pi, err := indexer.PrimaryIndexes()
	if err != nil || len(pi) < 1 {
		fmt.Printf("No primary index found")
		return
	}

	//fmt.Printf(" got primary index %s", pi.name)
	conn := datastore.NewIndexConnection(nil)
	go pi[0].ScanEntries(math.MaxInt64, datastore.UNBOUNDED, nil, conn)

	var entry *datastore.IndexEntry

	ok := true
	for ok {

		select {
		case entry, ok = <-conn.EntryChannel():
			if ok {
				fmt.Printf("\n primary key %v", entry.PrimaryKey)
			}
		}
	}
}
Esempio n. 5
0
func init() {
	logger := logger_golog.NewLogger(os.Stderr, logging.Info, false)
	logging.SetLogger(logger)
}
Esempio n. 6
0
func init() {
	logger, _ := log_resolver.NewLogger("golog")
	logging.SetLogger(logger)
}