Ejemplo n.º 1
0
// ProcessLog takes a Logvac or Stormpack log and breaks it apart into pieces that
// are then reconstructed in a 'digestible' way, colorized, and output to the
// terminal
func ProcessLog(log Log) {

	// t := time.Now(log.Time).Format(time.RFC822)
	// t, err := time.Parse("01/02 03:04:05PM '06 -0700", log.Time)
	// if err != nil {
	// 	fmt.Println("TIME BONK!", err)
	// }

	//
	subMatch := regexp.MustCompile(`^(\w+)\.(\S+)\s+(.*)$`).FindStringSubmatch(log.Content)

	// ensure a subMatch and ensure subMatch has a length of 4, since thats how many
	// matches we're expecting
	if subMatch != nil && len(subMatch) >= 4 {

		service := subMatch[1]
		process := subMatch[2]
		content := subMatch[3]

		//
		if _, ok := logProcesses[process]; !ok {
			logProcesses[process] = logColors[len(logProcesses)%len(logColors)]
		}

		// print.Color("[%v]%v - %v.%v :: %v[reset]", logProcesses[process], log.Time, service, process, content)
		printutil.Color("[%v]%v (%v) :: %v[reset]", logProcesses[process], service, process, content)

		// if we don't have a subMatch or its length is less than 4, just print w/e
		// is in the log
	} else {
		printutil.Color("[light_red]%v - %v[reset]", log.Time, log.Content)
	}
}
Ejemplo n.º 2
0
// TestColor
func TestColor(t *testing.T) {
	raw := "\x1b[31mtest color output\x1b[0m\x1b[0m\n"
	out := stdoutToString(func() { printutil.Color("[red]test color output[reset]") })
	if out != raw {
		t.Error(fmt.Sprintf("Expected '%q' got '%q'", raw, out))
	}
}
Ejemplo n.º 3
0
// authenticate
func authenticate(Userslug, password string) (string, string) {

	fmt.Printf("\nAttempting login for %v... ", Userslug)

	// get auth_token
	user, err := api.GetAuthToken(Userslug, password)
	if err != nil {
		printutil.Color("[red]failure![reset]")
		fmt.Println("Unable to login... please verify your username and password are correct.")
		os.Exit(1)
	}

	//
	if err := saveCredentials(user.ID, user.AuthenticationToken); err != nil {
		config.Fatal("[auth/auth] saveCredentials failed", err.Error())
	}

	//
	printutil.Color("[green]success![reset]")

	return user.ID, user.AuthenticationToken
}