Example #1
0
func init() {
	backend := logging.NewLogBackend(os.Stderr, "", 0)
	logging.SetBackend(backend)
	formatter := logging.MustStringFormatter("[%{time:15:04:05.000}] %{shortfile:18s}: %{color}[%{level:-5s}]%{color:reset} %{message}")
	logging.SetFormatter(formatter)
	logger = logging.MustGetLogger("orderer/kafka")
	logging.SetLevel(logging.INFO, "") // Silence debug-level outputs when testing
}
Example #2
0
func init() {
	var format = "%{color}%{time:15:04:05.000000} ▶ %{level:.4s} %{color:reset} %{message}"
	logBackend := logging.NewLogBackend(os.Stderr, "", 0)
	logging.SetFormatter(logging.MustStringFormatter(format))
	logging.SetBackend(logBackend)

	exp.Exp(metrics.DefaultRegistry)

}
Example #3
0
func initLogging(level logging.Level, color bool) {
	format := logging.MustStringFormatter(logFormat)
	logging.SetFormatter(format)
	for _, s := range logModules {
		logging.SetLevel(level, s)
	}
	stdout := logging.NewLogBackend(os.Stdout, "", 0)
	stdout.Color = color
	logging.SetBackend(stdout)
}
Example #4
0
// initialize logging using this LogConfig;
// it panics if l.Format is invalid or l.Level is invalid
func (l *LogConfig) InitLogger() {
	l.initLevel()

	format := logging.MustStringFormatter(l.Format)
	logging.SetFormatter(format)
	for _, s := range l.Modules {
		logging.SetLevel(l.level, s)
	}
	stdout := logging.NewLogBackend(os.Stdout, "", 0)
	stdout.Color = l.Colors
	logging.SetBackend(stdout)
}
Example #5
0
func initLogging(level logging.Level, color bool) {
	format := logging.MustStringFormatter(logFormat)
	logging.SetFormatter(format)
	bk := logging.NewLogBackend(os.Stdout, "", 0)
	bk.Color = true
	bkLvd := logging.AddModuleLevel(bk)
	for _, s := range logModules {
		bkLvd.SetLevel(level, s)
	}

	logging.SetBackend(bkLvd)
}
func init() {
	var format = "%{color}%{time:15:04:05.000000} ▶ %{level:.4s} %{color:reset} %{message}"
	logBackend := logging.NewLogBackend(os.Stderr, "", 0)
	logging.SetFormatter(logging.MustStringFormatter(format))
	logging.SetBackend(logBackend)

	input.SetLogger(log)
	tbl.SetLogger(log)
	route.SetLogger(log)
	destination.SetLogger(log)
	telnet.SetLogger(log)
	web.SetLogger(log)
}
Example #7
0
func configureLogging(colorLogs bool) {
	golog.SetFormatter(golog.MustStringFormatter("[0x%{id:x}] [%{level}] [%{module}] %{message}"))
	stdoutLogBackend := golog.NewLogBackend(os.Stdout, "", stdlog.LstdFlags|stdlog.Lshortfile)
	stdoutLogBackend.Color = colorLogs

	golog.SetBackend(stdoutLogBackend)
	golog.SetLevel(golog.DEBUG, "")

	// test logs
	jabberwocky, err := ioutil.ReadFile("the_jabberwocky.txt")
	if err != nil {
		log.Warning("Failed to read \"The Jabberwocky\", it looks like nonsense")
		return
	}
	log.Notice(fmt.Sprintf("\n\n%s", string(jabberwocky)))
}
Example #8
0
func main() {
	var loglevel string

	client := &clientImpl{doneChan: make(chan struct{})}

	backend := logging.NewLogBackend(os.Stderr, "", 0)
	logging.SetBackend(backend)
	formatter := logging.MustStringFormatter("[%{time:15:04:05}] %{shortfile:18s}: %{color}[%{level:-5s}]%{color:reset} %{message}")
	logging.SetFormatter(formatter)
	logger = logging.MustGetLogger(pkgName)

	flag.StringVar(&loglevel, "loglevel", "info",
		"The logging level. (Suggested values: info, debug)")
	flag.StringVar(&client.config.server, "server",
		"127.0.0.1:7050", "The RPC server to connect to.")
	flag.StringVar(&client.config.cmd.cmd, "cmd", "new-chain",
		"The action that this client is requesting via the config transaction.")
	flag.StringVar(&client.config.cmd.args.creationPolicy, "creationPolicy", "AcceptAllPolicy",
		"In case of a new-chain command, the chain createion policy this request should be validated against.")
	flag.StringVar(&client.config.cmd.args.chainID, "chainID", "NewChainID",
		"In case of a new-chain command, the chain ID to create.")
	flag.Parse()

	client.config.logLevel, _ = logging.LogLevel(strings.ToUpper(loglevel))
	logging.SetLevel(client.config.logLevel, logger.Module)

	conn, err := grpc.Dial(client.config.server, grpc.WithInsecure())
	if err != nil {
		logger.Fatalf("Client did not connect to %s: %v", client.config.server, err)
	}
	defer conn.Close()
	client.rpc = ab.NewAtomicBroadcastClient(conn)

	switch client.config.cmd.cmd {
	case "new-chain":
		envelope := newChainRequest(client.config.cmd.args.creationPolicy, client.config.cmd.args.chainID)
		logger.Infof("Requesting the creation of chain \"%s\"", client.config.cmd.args.chainID)
		client.broadcast(envelope)
	default:
		panic("Invalid cmd given")
	}
}
Example #9
0
func getLogger(name string, logConfig LogConfig) *logger.Logger {
	mainLogger.Info("Make logger of %s at file %s", name, logConfig.Filename)
	log1 := logger.MustGetLogger(name)

	var leveledBackend logger.LeveledBackend
	f, err := logger.NewStringFormatter("%{shortfile} %{time:2006-01-02T15:04:05} %{level:.1s} %{id:04d} %{module} %{message}")
	if err != nil {
		mainLogger.Info("failed to set format: %s", err)
	}
	logger.SetFormatter(f)

	if logConfig.Filename != "" {
		logFileName := logConfig.Filename

		logFile, err := os.OpenFile(logFileName, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
		backend := logger.NewLogBackend(logFile, "", 0)
		if err != nil {
			mainLogger.Error("Failed to open log file - " + logFileName)
			panic(err)
		} else {
			leveledBackend = logger.AddModuleLevel(backend)
		}
	} else {
		backend := logger.NewLogBackend(os.Stdout, "", 0)
		leveledBackend = logger.AddModuleLevel(backend)

	}

	switch logConfig.Level {
	case "debug":
		leveledBackend.SetLevel(logger.NOTICE, name)
	case "error":
		logger.SetLevel(logger.ERROR, name)
	case "info":
		logger.SetLevel(logger.INFO, name)
	case "warn":
		logger.SetLevel(logger.WARNING, name)
	}

	log1.SetBackend(leveledBackend)
	return log1
}
Example #10
0
func Configure() {
	golog.SetFormatter(golog.MustStringFormatter("[0x%{id:x}] [%{level}] [%{module}] %{message}"))
	stdoutLogBackend := golog.NewLogBackend(os.Stdout, "", stdlog.LstdFlags|stdlog.Lshortfile)
	stdoutLogBackend.Color = true
	golog.SetLevel(defaultLevel, "")

	// NOTE these file permissions are restricted by umask, so they probably won't work right.
	err := os.MkdirAll("./log", 0775)
	if err != nil {
		panic(err)
	}
	logFile, err := os.OpenFile("./log/zendesk-livestats.log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664)
	if err != nil {
		panic(err)
	}

	fileLogBackend := golog.NewLogBackend(logFile, "", stdlog.LstdFlags|stdlog.Lshortfile)
	fileLogBackend.Color = false

	golog.SetBackend(stdoutLogBackend, fileLogBackend)
}
Example #11
0
func initLog(logConfig map[string]interface{}) {

	mainLogger.Info("LogConfig: %v", logConfig)
	_, ok := logConfig["level"]
	if ok {
		switch logConfig["level"].(string) {
		case "debug":
			logger.SetLevel(logger.NOTICE, moduleName)
		case "error":
			logger.SetLevel(logger.ERROR, moduleName)
		case "info":
			logger.SetLevel(logger.INFO, moduleName)
		case "warn":
			logger.SetLevel(logger.WARNING, moduleName)
		}
	}

	f, err := logger.NewStringFormatter("%{shortfile} %{time:2006-01-02T15:04:05} %{level:.1s} %{id:04d} %{module} %{message}")
	if err != nil {
		mainLogger.Info("failed to set format: %s", err)
	}
	logger.SetFormatter(f)

	_, ok = logConfig["file"]
	if ok {
		logFileName := logConfig["file"].(string)

		logFile, err := os.OpenFile(logFileName, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
		backend := logger.NewLogBackend(logFile, "", 0)
		if err != nil {
			mainLogger.Error("Failed to open log file - " + logFileName)
			panic(err)
		} else {
			logger.SetBackend(backend)
		}
	} else {
		backend := logger.NewLogBackend(os.Stdout, "", 0)
		logger.SetBackend(backend)
	}
}
Example #12
0
func SetLogging(cfg Config) (err error) {
	var file *os.File
	file = os.Stdout

	if cfg.Logfile != "" {
		file, err = os.OpenFile(cfg.Logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
		if err != nil {
			log.Fatal(err)
		}
	}
	logBackend := logging.NewLogBackend(file, "",
		stdlog.LstdFlags|stdlog.Lmicroseconds|stdlog.Lshortfile)
	logging.SetBackend(logBackend)

	logging.SetFormatter(logging.MustStringFormatter("%{level}: %{message}"))

	lv, err := logging.LogLevel(cfg.Loglevel)
	if err != nil {
		panic(err.Error())
	}
	logging.SetLevel(lv, "")

	return
}
Example #13
0
func main() {
	var format = logging.MustStringFormatter("%{level} %{message}")
	logging.SetFormatter(format)
	logging.SetLevel(logging.INFO, "iloveptt")

	usr, _ := user.Current()
	baseDir = fmt.Sprintf("%v/Pictures/iloveptt", usr.HomeDir)

	var workerNum int
	rootCmd := &cobra.Command{
		Use:   "iloveptt",
		Short: "Download all the images in given post url",
		Run: func(cmd *cobra.Command, args []string) {
			page := 0
			hrefs := parsePttBoardIndex(page)

			scanner := bufio.NewScanner(os.Stdin)
			quit := false

			for !quit {
				fmt.Print("ptt:> ")

				if !scanner.Scan() {
					break
				}

				line := scanner.Text()
				parts := strings.Split(line, " ")
				cmd := parts[0]
				args := parts[1:]

				switch cmd {
				case "quit":
					quit = true
				case "n":
					page = page + 1
					hrefs = parsePttBoardIndex(page)
				case "p":
					if page > 0 {
						page = page - 1
					}
					hrefs = parsePttBoardIndex(page)
				case "s":
					page = 0
					hrefs = parsePttBoardIndex(page)
				case "o":
					open.Run(filepath.FromSlash(baseDir))
				case "d":
					if len(args) == 0 {
						fmt.Println("You don't input any article index. Input as 'd 1'")
						continue
					}

					index, err := strconv.ParseUint(args[0], 0, 0)
					if err != nil {
						fmt.Println(err)
						continue
					}
					if int(index) >= len(hrefs) {
						fmt.Println("Invalid index")
						continue
					}

					if threadId.Match([]byte(hrefs[index])) {
						crawler(hrefs[index], 25)
						fmt.Println("Done!")
					} else {
						fmt.Println("Unsupport url:", hrefs[index])
					}
				default:
					fmt.Println("Unrecognized command:", cmd, args)
				}
			}
		},
	}

	rootCmd.Flags().IntVarP(&workerNum, "worker", "w", 25, "Number of workers")
	rootCmd.Execute()
}
Example #14
0
func main() {
	var format = logging.MustStringFormatter("%{level} %{message}")
	logging.SetFormatter(format)
	logging.SetLevel(logging.INFO, "iloveck101")

	usr, _ := user.Current()
	baseDir = fmt.Sprintf("%v/Pictures/iloveck101", usr.HomeDir)

	var postUrl string
	var workerNum int

	rootCmd := &cobra.Command{
		Use:   "iloveck101",
		Short: "Download all the images in given post url",
		Run: func(cmd *cobra.Command, args []string) {
			crawler(postUrl, workerNum)
		},
	}
	rootCmd.Flags().StringVarP(&postUrl, "url", "u", "http://ck101.com/thread-2876990-1-1.html", "Url of post")
	rootCmd.Flags().IntVarP(&workerNum, "worker", "w", 25, "Number of workers")

	searchCmd := &cobra.Command{
		Use:   "search",
		Short: "Download all the images in given post url",
		Run: func(cmd *cobra.Command, args []string) {
			page := 0
			keyword := args[0]
			hrefs := printGoogleResult(keyword, page)

			scanner := bufio.NewScanner(os.Stdin)
			quit := false

			for !quit {
				fmt.Print("ck101> ")

				if !scanner.Scan() {
					break
				}

				line := scanner.Text()
				parts := strings.Split(line, " ")
				cmd := parts[0]
				args := parts[1:]

				switch cmd {
				case "quit":
					quit = true
				case "n":
					page = page + 1
					hrefs = printGoogleResult(keyword, page)
				case "p":
					if page > 0 {
						page = page - 1
					}
					hrefs = printGoogleResult(keyword, page)
				case "s":
					page = 0
					hrefs = printGoogleResult(args[0], page)
				case "o":
					open.Run(baseDir)
				case "d":
					index, err := strconv.ParseUint(args[0], 0, 0)
					if err != nil {
						fmt.Println(err)
						continue
					}
					if int(index) >= len(hrefs) {
						fmt.Println("Invalid index")
						continue
					}

					// Only support url with format ck101.com/thread-xxx
					if threadId.Match([]byte(hrefs[index])) {
						crawler(hrefs[index], 25)
						fmt.Println("Done!")
					} else {
						fmt.Println("Unsupport url:", hrefs[index])
					}
				default:
					fmt.Println("Unrecognized command:", cmd, args)
				}
			}
		},
	}

	rootCmd.AddCommand(searchCmd)
	rootCmd.Execute()
}
Example #15
0
func main() {
	logBackend := logging.NewLogBackend(os.Stderr, "", 0)
	logging.SetBackend(logBackend)
	logging.SetFormatter(logging.MustStringFormatter(format))
	logging.SetLevel(logging.NOTICE, "streamLog")
	homeDir := os.Getenv("HOME")

	app := cli.NewApp()
	app.Name = "tarzan"
	app.Usage = "naive cached automated build implementation"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "p,port",
			Value: "3000",
			Usage: "port to serve tarzan on",
		},
		cli.StringFlag{
			Name:  "alt-registry",
			Value: "",
			Usage: "alternative registry to push images to instead of Docker Hub",
		},
		cli.StringFlag{
			Name:  "secret",
			Value: "",
			Usage: "secret to use when receiving webhook payload",
		},
		cli.StringFlag{
			Name:  "hub-name",
			Value: "",
			Usage: "specify a username on Docker Hub which is different than your Github handle",
		},
		cli.StringFlag{
			Name:  "docker-binary-name",
			Value: "docker",
			Usage: "specify the docker binary name (if it is not docker in $PATH)",
		},
	}

	app.Action = func(c *cli.Context) {
		dockerBinary := c.String("docker-binary-name")
		if err := loadBuildStatus(); err != nil {
			fmt.Fprintln(os.Stderr, "Error loading build status (did your repos/ dir get corrupted?):", err)
			os.Exit(1)
		}
		if _, err := os.Stat(fmt.Sprintf("%s/.dockercfg", homeDir)); err != nil {
			if os.IsNotExist(err) {
				log.Warning("Detected no Docker Hub login.  Please log in now.")
				cmd := exec.Command(dockerBinary, "login")
				cmd.Stdin = os.Stdin
				cmd.Stdout = os.Stdout
				cmd.Stderr = os.Stderr
				if err := cmd.Run(); err != nil {
					fmt.Fprintln(os.Stderr, "Error running docker login")
					os.Exit(1)
				}
			}
		}
		r := render.New(render.Options{})
		router := mux.NewRouter()
		router.HandleFunc("/build", BuildHookReceiver(c, r, dockerBinary)).Methods("POST")
		router.HandleFunc("/buildList", MakeBuildListHandler(r)).Methods("GET")

		n := negroni.Classic()
		n.Use(negroni.NewStatic(http.Dir("frontend/")))
		n.UseHandler(router)
		n.Run(fmt.Sprintf(":%s", c.String("port")))
	}

	app.Run(os.Args)
}
Example #16
0
File: main.go Project: pulcy/gluon
func init() {
	logging.SetFormatter(logging.MustStringFormatter("[%{level:-5s}] %{message}"))
}
Example #17
0
File: main.go Project: hectorj/godm
func main() {
	checkGo15VendorActivated()

	cli.VersionFlag.Name = "version" // We use "v" for verbose
	app := cli.NewApp()
	app.Name = "godm"
	app.Usage = "Package Manager for Go 1.5+"
	app.Authors = []cli.Author{
		{
			Name:  "HectorJ",
			Email: "*****@*****.**",
		},
	}
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "verbose",
			Usage: "Verbose output",
		},
	}
	app.EnableBashCompletion = true
	app.Before = func(c *cli.Context) error {
		logging.SetFormatter(logFormatter)
		backend := logging.AddModuleLevel(logging.NewLogBackend(os.Stderr, "", 0))
		if c.GlobalBool("verbose") {
			backend.SetLevel(logging.DEBUG, "")
		} else {
			backend.SetLevel(logging.WARNING, "")
		}

		Log.SetBackend(backend)
		return nil
	}
	app.Commands = []cli.Command{
		{
			Name:   "clean",
			Usage:  "Removes vendors that are not imported in the current project. Outputs the import paths of vendors successfully removed.",
			Action: clean,
		},
		{
			Name:  "vendor",
			Usage: "Vendors imports that are not vendored yet in the current project. Outputs the import paths of vendors successfully added.",
			Flags: []cli.Flag{
			// Removed for now. Here is the current behavior :
			// - For Git projects : we start from the root dir and do scan recursively all sub-packages (except vendors)
			// - For "no-vcl" projects : we only scan the current dir we're in
			//				cli.BoolFlag{
			//					Name:  "r,recursive",
			//					Usage: "Scan dirs recursively for sub-packages",
			//				},

			// Removed for now. Here is the current behavior :
			// We exclude "vendor" directories
			//				cli.StringSliceFlag{
			//					Name:  "e,exclude",
			//					Usage: "Files/Directories names to exclude from scanning, as regexp.",
			//				},
			},
			Action: vendor,
		},
		{
			Name:    "remove",
			Aliases: []string{"rm"},
			Usage:   "Unvendors an import path. Takes a single import path as argument.",
			Flags:   []cli.Flag{
			// Removed for now, as there is no confirmation asked anywhere
			//				cli.BoolFlag{
			//					Name:  "y,yes",
			//					Usage: "Remove the submodule without asking any confirmation",
			//				},
			},
			Action: remove,
			BashComplete: func(c *cli.Context) {
				if len(c.Args()) > 0 {
					return
				}
				project, err := godm.NewLocalProject(path.Dir(os.Args[0]), "")
				if err != nil {
					return
				}

				vendors, err := project.GetVendors()

				if err != nil {
					return
				}

				for importPath := range vendors {
					fmt.Println(importPath)
				}
			},
		},
	}
	app.RunAndExitOnError()
}