Ejemplo n.º 1
0
func main() {
	// in response to some conditional
	log = dog.NewDog(dog.WARN)

	log.Warn = dog.CreateLog(dog.FgRed, "> ")
	log.Warn("Typical customization")

	log.Warn = dog.CreateLog("", dog.FgRed+">"+dog.TR+" ")
	log.Warn("Even more minimal")

	log.Warn = dog.CreateLog(dog.FgYellow+dog.Reverse, "🐺  ")
	log.Warn("Dawg, this custom log format is rockin the CLI!!1")
}
Ejemplo n.º 2
0
package main

import "github.com/JonahBraun/dog"

var log = dog.NewDog(dog.DEBUG)

func main() {
	number := 8
	msg := "example error message from some library"

	// any variables can be appended to any of the log calls
	log.Debug("Might be needed for advanced debugging")
	log.Info("Your number is", number)
	log.Warn("Possibly an issue")
	log.Err("This should't be happening…", msg)

	// Fatal returns a call to os.Exit(int) so that you can easily exit
	log.Fatal("We need to exit")(1)
}
Ejemplo n.º 3
0
func configSetup() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Usage = func() {
		fmt.Println("WaGo (Watch, Go) build tool. Version", VERSION)
		flag.PrintDefaults()
	}

	// TODO: this should check for actions
	if len(os.Args) < 2 {
		flag.Usage()
		log.Fatal("You must specify an action")(1)
	}

	webBase := flag.String("webbase", "", "Deprecated, use webroot.")
	webServer := flag.String("web", "", "Deprecated, use http or http2.")

	flag.Parse()

	if *verbose {
		log = dog.NewDog(dog.DEBUG)
	} else if *quiet {
		log = dog.NewDog(dog.WARN)
	} else {
		log = dog.NewDog(dog.INFO)
	}

	if *webBase != "" {
		log.Warn("-webbase is deprecated, use -webroot")
		*webRoot = *webBase
	}
	if *webServer != "" {
		log.Warn("-web is deprecated, use -http or -h2")
		*httpPort = *webServer
	}

	if len(*shell) == 0 {
		*shell = os.Getenv("SHELL")
		if len(*shell) == 0 {
			*shell = "/bin/sh"
		}
	}
	log.Debug("Using shell", *shell)

	if (len(*daemonTrigger) > 0) && (*daemonTimer > 0) {
		log.Fatal("Both daemon trigger and timer specified, use only one")(1)
	}

	if (len(*daemonTrigger) > 0 || *daemonTimer > 0) && len(*daemonCmd) == 0 {
		log.Fatal("Specify a daemon command to use the trigger or timer")(1)
	}

	if len(*buildCmd) == 0 && len(*daemonCmd) == 0 && !*fiddle && len(*postCmd) == 0 && len(*url) == 0 && len(*webServer) == 0 && len(*httpPort) == 0 && len(*http2Port) == 0 {
		flag.Usage()
		log.Fatal("You must specify an action")(1)
	}

	if *fiddle {
		if *httpPort == "" {
			*httpPort = ":8420"
		}
		if *http2Port == "" {
			*http2Port = ":8421"
		}
		if *url == "" {
			*url = "http://localhost" + *webServer + "/"
		}
	}

	if *targetDir == "" {
		cwd, err := os.Getwd()
		if err != nil {
			panic(err)
		}
		targetDir = &cwd
	}

	if (*keyFile != "" && *certFile == "") || (*certFile != "" && *keyFile == "") {
		log.Fatal("Set both key and cert or none to use default.")(1)
	}

	log.Debug("Target dir:", *targetDir)
}