Example #1
0
func main() {
	//Revel Example

	//first set some color information
	info := gocolorize.NewColor("green")
	warning := gocolorize.NewColor("yellow")

	critical := gocolorize.NewColor("black+u:red")
	//We could also do this
	//critical.ToggleUnderline()

	//helper functions to shorten code
	i := info.Paint
	w := warning.Paint
	c := critical.Paint

	//Define the look/feel of the INFO logger
	INFO = log.New(os.Stdout, i("INFO "), log.Ldate|log.Lmicroseconds|log.Lshortfile)
	WARNING = log.New(os.Stdout, w("WARNING "), log.Ldate|log.Lmicroseconds|log.Lshortfile)
	CRITICAL = log.New(os.Stdout, c("CRITICAL")+" ", log.Ldate|log.Lmicroseconds|log.Lshortfile)

	//print out some messages, note the i wrappers for yellow text on the actual info string
	INFO.Println(i("Loaded module x"))
	INFO.Println(i("Loaded module y"))
	WARNING.Println(w("Failed to load module z"))

	e := MyError{What: "Failed"}

	CRITICAL.Println(c("Failed with an error code:", e))

}
Example #2
0
func (l *loggingT) getColorByte(s severity, b []byte) []byte {
	var c gocolorize.Colorize
	switch s {
	case warningLog:
		c = gocolorize.NewColor("yellow")
	case errorLog:
		c = gocolorize.NewColor("red")
	case fatalLog:
		c = gocolorize.NewColor("magenta")
	default:
		c = gocolorize.NewColor("green")
	}
	return []byte(c.Paint(string(b)))
}
Example #3
0
func showDiff(oldText, newText string) {
	dmp := diffmatchpatch.New()
	diffs := dmp.DiffMain(oldText, newText, true)

	for _, diff := range diffs {
		switch diff.Type {
		case diffmatchpatch.DiffInsert:
			color := gocolorize.NewColor("green")
			printLinesWithPrefix(color.Paint("+"), diff.Text)
		case diffmatchpatch.DiffDelete:
			color := gocolorize.NewColor("red")
			printLinesWithPrefix(color.Paint("-"), diff.Text)
		}
	}
}
Example #4
0
func main() {
	loggers.IsDebug = os.Getenv("GBW_DEBUG") == "1"
	fmt.Println(gocolorize.NewColor("magenta").Paint("gobuildweb > Build a Golang web application.\n"))

	cmds := map[string]Command{
		"run":  commandRun,
		"dist": commandDist,
	}
	flag.Parse()
	args := flag.Args()
	if len(args) == 0 {
		usage()
	}
	if cmd, ok := cmds[args[0]]; !ok {
		usage()
	} else {
		if fi, err := os.Stat("project.toml"); os.IsNotExist(err) {
			loggers.ERROR.Fatalf("Please provide a project.toml for web project.")
		} else if err != nil {
			loggers.ERROR.Fatalf("Accessing project.toml file error, %v.", err)
		} else if fi.IsDir() {
			loggers.ERROR.Fatalf("project.toml cannot be a directory.")
		}

		if _, err := toml.DecodeFile("project.toml", &rootConfig); err != nil {
			loggers.ERROR.Fatalf("Cannot decode the project.toml into TOML format, %v", err)
		}
		loggers.SUCC.Printf("Loaded project.toml... %s", rootConfig.Package.Name)
		if err := cmd(args[1:]); err != nil {
			loggers.ERROR.Fatalf("Executing command [%v] error, %v", args[0], err)
		}
	}
}
Example #5
0
func Parse() {
	if runtime.GOOS == "windows" {
		gocolorize.SetPlain(true)
	}

	var err = gcfg.ReadFileInto(&AppCfg, "App.cfg")
	if err != nil {
		errorf("Missing App.cfg")
		os.Exit(1)
	}

	fmt.Fprintf(os.Stdout, gocolorize.NewColor("Blue").Paint(AppCfg.App.Header))
	flag.Usage = func() { usage(1) }
	flag.Parse()
	args := flag.Args()

	if len(args) < 1 || args[0] == "help" {
		if len(args) == 1 {
			usage(0)
		}
		if len(args) > 1 {
			for _, cmd := range commands {
				if cmd.Name() == args[1] {
					tmpl(os.Stdout, AppCfg.Template.helpTemplate, cmd)
					return
				}
			}
		}
		usage(2)
	}

	// Commands use panic to abort execution when something goes wrong.
	// Panics are logged at the point of error. Ignore those.
	defer func() {
		if err := recover(); err != nil {
			if _, ok := err.(LoggedError); !ok {
				// This panic was not expecred/logged.
				panic(err)
			}
			os.Exit(1)
		}
	}()

	for _, cmd := range commands {
		if cmd.Name() == args[0] {
			cmd.Run(args[1:])
			return
		}
	}

	errorf("Unknown command.\n Run '%q help' for usage", args[0])
}
Example #6
0
func main() {
	// one way to define a stateful colorizer
	var green gocolorize.Colorize
	green.SetColor(gocolorize.Green)
	g := green.Paint

	// Another way to do it
	red := gocolorize.Colorize{Fg: gocolorize.Red}
	r := red.Paint

	// now with string construction
	green_black := gocolorize.Colorize{Fg: gocolorize.Blue}
	// toggle attributes
	green_black.ToggleUnderline()
	b := green_black.Paint

	//all in 1 line
	c := gocolorize.NewColor("yellow:black").Paint

	//r := gocolorize.COLOR_RED

	fmt.Println(b("On the twelfth day of Christmas"))
	fmt.Println(b("my true love sent to me:"))
	fmt.Println(g("Twelve"), c("Drummers"), r("Drumming"))
	fmt.Println(g("Eleven"), c("Pipers"), r("Piping"))
	fmt.Println(g("Ten"), c("Lords"), r("a Leaping"))
	fmt.Println(g("Nine"), c("Ladies"), r("Dancing"))
	fmt.Println(g("Eight"), c("Maids"), r("a Milking"))
	fmt.Println(g("Seven"), c("Swans"), r("a Swimming"))
	fmt.Println(g("Six"), c("Geese"), r("a Laying"))
	fmt.Println(g("Five"), c("Golden"), r("Rings"))
	fmt.Println(g("Four"), c("Calling"), r("Birds"))
	fmt.Println(g("Three"), c("French"), r("Hens"))
	fmt.Println(g("Two"), c("Turtle"), r("Doves"))
	fmt.Println(b("and a Partridge in a Pear Tree"))

}
Example #7
0
	HttpSslKey  string // e.g. "/path/to/key.pem"

	// All cookies dropped by the framework begin with this prefix.
	CookiePrefix string
	// Cookie domain
	CookieDomain string
	// Cookie flags
	CookieHttpOnly bool
	CookieSecure   bool

	// Delimiters to use when rendering templates
	TemplateDelims string

	//Logger colors
	colors = map[string]gocolorize.Colorize{
		"trace": gocolorize.NewColor("magenta"),
		"info":  gocolorize.NewColor("green"),
		"warn":  gocolorize.NewColor("yellow"),
		"error": gocolorize.NewColor("red"),
	}

	error_log = revelLogs{c: colors["error"], w: os.Stderr}

	// Loggers
	TRACE = log.New(ioutil.Discard, "TRACE ", log.Ldate|log.Ltime|log.Lshortfile)
	INFO  = log.New(ioutil.Discard, "INFO  ", log.Ldate|log.Ltime|log.Lshortfile)
	WARN  = log.New(ioutil.Discard, "WARN  ", log.Ldate|log.Ltime|log.Lshortfile)
	ERROR = log.New(&error_log, "ERROR ", log.Ldate|log.Ltime|log.Lshortfile)

	Initialized bool
Example #8
0
	Long: `sync checks the GOPATH for consistency with the given package's GLOCKFILE

For example:

	glock sync github.com/robfig/glock

It verifies that each entry in the GLOCKFILE is at the expected revision.
If a dependency is not at the expected revision, it is re-downloaded and synced.
Commands are built if necessary.
`,
}

var (
	color = flag.Bool("color", true, "if true, colorize terminal output")

	info     = gocolorize.NewColor("green").Paint
	warning  = gocolorize.NewColor("yellow").Paint
	critical = gocolorize.NewColor("red").Paint

	disabled = func(args ...interface{}) string { return fmt.Sprint(args...) }
)

func init() {
	cmdSync.Run = runSync // break init loop
}

func runSync(cmd *Command, args []string) {
	if len(args) == 0 {
		cmdSync.Usage()
		return
	}
Example #9
0
func init() {
	INFO = log.New(os.Stdout, "(gbw) [INFO] ", 0)
	SUCC = log.New(&ColoredLogger{gocolorize.NewColor("green"), os.Stdout}, "(gbw) [SUCC] ", 0)
	WARN = log.New(&ColoredLogger{gocolorize.NewColor("yellow"), os.Stdout}, "(gbw) [WARN] ", 0)
	ERROR = log.New(&ColoredLogger{gocolorize.NewColor("red"), os.Stdout}, "(gbw) [ERROR] ", 0)
}
Example #10
0
package cli

import (
	"fmt"

	"github.com/agtorre/gocolorize"
	"github.com/kr/beanstalk"
)

var TitleStyle = gocolorize.NewColor("green")
var InfoStyle = gocolorize.NewColor("yellow")

type Command struct {
	Host string `short:"h" long:"host" description:"beanstalkd host addr." required:"true" default:"localhost:11300"`

	conn *beanstalk.Conn
}

func (c *Command) Init() error {
	var err error
	c.conn, err = beanstalk.Dial("tcp", c.Host)
	if err != nil {
		return err
	}

	return nil
}

func (c *Command) PrintJob(id uint64, body []byte) error {
	s, err := c.conn.StatsJob(id)
	if err != nil {
Example #11
0
package wlog

import (
	"fmt"
	"github.com/agtorre/gocolorize"
	"github.com/mabetle/mcore/mterm"
)

var (
	trace = gocolorize.NewColor("magenta")
	debug = gocolorize.NewColor("cyan")
	info  = gocolorize.NewColor("green")
	warn  = gocolorize.NewColor("yellow")
	err   = gocolorize.NewColor("red")

	//helper functions to longen code
	d = debug.Paint
	i = info.Paint
	w = warn.Paint
	e = err.Paint
	t = trace.Paint
)

func GetLevelColorMsg(level string, v ...interface{}) string {
	// default no color.
	msg := fmt.Sprint(v...)
	levelLevel := GetStringLevel(level)

	// xterm can show color.
	if mterm.IsXterm() {
		switch levelLevel {
Example #12
0
	"fmt"
	"strconv"
	"strings"

	"github.com/agtorre/gocolorize"
	"github.com/mcuadros/termtable"
)

const (
	HighSeverity = iota
	NormalSeverity
	LowSeverity
)

var TubeStatsRetrievalError = errors.New("Unable to retrieve tube stats")
var HighSeverityStyle = gocolorize.NewColor("white:red")
var NormalSeverityStyle = gocolorize.NewColor("green")

type StatsCommand struct {
	Tubes string `short:"t" long:"tubes" description:"tubes to be listed (separated by ,). By default all are listed"`

	Command
}

func (c *StatsCommand) Execute(args []string) error {
	if err := c.Init(); err != nil {
		return err
	}

	if err := c.PrintStats(); err != nil {
		return err