コード例 #1
0
ファイル: config.go プロジェクト: rdoorn/ghostbox
// GetLog gets log handler
func GetLog(level logging.Level) (l *logging.Logger) {
	l = logging.MustGetLogger("ghostbox")
	var customLogFormat = logging.MustStringFormatter(
		"%{color}%{time:2006-01-02 15:04:05.000} %{level:.4s} %{shortfunc:16s} ▶ %{id:03x}%{color:reset} %{message}",
	)
	backend1 := logging.NewLogBackend(os.Stderr, "", 0)
	backend2 := logging.NewLogBackend(os.Stdout, "", 0)
	backend2Formatter := logging.NewBackendFormatter(backend2, customLogFormat)
	backend1Leveled := logging.AddModuleLevel(backend1)
	backend1Leveled.SetLevel(logging.ERROR, "")
	backend2Leveled := logging.AddModuleLevel(backend2Formatter)
	backend2Leveled.SetLevel(level, "") // 0=crit 1=err 2=warn 3=notice 4=info 5=debug
	logging.SetBackend(backend1Leveled, backend2Leveled)
	return
}
コード例 #2
0
func setUpLogging(logLevel logging.Level) {
	backend := logging.NewLogBackend(os.Stderr, "", 0)
	backendFormatted := logging.NewBackendFormatter(backend, logFormat)
	backendLeveled := logging.AddModuleLevel(backendFormatted)
	backendLeveled.SetLevel(logLevel, "")
	logging.SetBackend(backendLeveled)
}
コード例 #3
0
ファイル: logger.go プロジェクト: myshkin5/netspel
func init() {
	Logger = gologging.MustGetLogger("netspel")
	format := gologging.MustStringFormatter("%{time:2006-01-02T15:04:05.000000Z} %{level} %{message}")
	backend := gologging.NewLogBackend(os.Stdout, "", 0)
	backendFormatter := gologging.NewBackendFormatter(backend, format)
	LogLevel = gologging.AddModuleLevel(backendFormatter)
	gologging.SetBackend(LogLevel)
}
コード例 #4
0
ファイル: logging.go プロジェクト: jmptrader/talaria
func init() {
	syncRoot = &sync.RWMutex{}
	format := gologging.MustStringFormatter("%{color}%{time:15:04:05:000} %{shortfunc} > %{level:.4s} %{id:03x}%{color:reset} %{message}")
	backend := gologging.NewLogBackend(os.Stdout, "", 0)
	backendFormatter := gologging.NewBackendFormatter(backend, format)
	backendLeveled = gologging.AddModuleLevel(backendFormatter)
	backendLeveled.SetLevel(gologging.INFO, "")
	gologging.SetBackend(backendLeveled)
}
コード例 #5
0
ファイル: buflog.go プロジェクト: vozhyk-/gohan
// SetUpLogging sets up logging to output for the test framework
func SetUpLogging(output io.Writer) {
	backend := logging.NewLogBackend(output, "", 0)
	format := logging.MustStringFormatter(
		"%{color}%{time:15:04:05.000}: %{module} %{level} %{color:reset} %{message}")
	backendFormatter := logging.NewBackendFormatter(backend, format)
	leveledBackendFormatter := logging.AddModuleLevel(backendFormatter)
	leveledBackendFormatter.SetLevel(logging.INFO, "")
	leveledBackendFormatter.SetLevel(logging.DEBUG, "extest")
	logging.SetBackend(leveledBackendFormatter)
}
コード例 #6
0
ファイル: framework.go プロジェクト: masaki-saeki/gohan
func setUpLogging() {
	backend := logging.NewLogBackend(os.Stderr, "", 0)
	format := logging.MustStringFormatter(
		"%{color}%{time:15:04:05.000}: %{module} %{level} %{color:reset} %{message}")
	backendFormatter := logging.NewBackendFormatter(backend, format)
	leveledBackendFormatter := logging.AddModuleLevel(backendFormatter)
	leveledBackendFormatter.SetLevel(logging.CRITICAL, "")
	leveledBackendFormatter.SetLevel(logging.DEBUG, "extest")
	logging.SetBackend(leveledBackendFormatter)
}
コード例 #7
0
ファイル: main.go プロジェクト: artpar/greconcile
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
}
コード例 #8
0
ファイル: config.go プロジェクト: shishkander/luci-go
func (lc *LoggerConfig) newGoLogger() *gol.Logger {
	// Leveled formatted file backend.
	backend := gol.AddModuleLevel(
		gol.NewBackendFormatter(
			gol.NewLogBackend(lc.Out, "", 0),
			gol.MustStringFormatter(lc.Format)))
	backend.SetLevel(lc.Level, "")
	logger := gol.MustGetLogger("")
	logger.SetBackend(backend)
	return logger
}
コード例 #9
0
ファイル: logger.go プロジェクト: kei-yamazaki/loggregator
func SetSysLogger(syslog string) {
	syslogBackend, err := gologging.NewSyslogBackend(syslog)
	if err != nil {
		panic(err)
	}
	backendFormatter := gologging.NewBackendFormatter(syslogBackend, format)
	syslogLeveledBackend := gologging.AddModuleLevel(backendFormatter)
	backends = append(backends, syslogLeveledBackend)

	gologging.SetBackend(backends...)
}
コード例 #10
0
ファイル: logging.go プロジェクト: wfernandes/IoT
func init() {
	Log = Logger{
		log: gologging.MustGetLogger("default"),
	}

	format := gologging.MustStringFormatter(`%{shortfile} %{color} %{time:2006-01-02T15:04:05.000000Z} %{level:.4s} %{color:reset} %{message}`)
	backend := gologging.NewLogBackend(os.Stdout, "", 0)
	backendFormatter := gologging.NewBackendFormatter(backend, format)
	leveledBackend = gologging.AddModuleLevel(backendFormatter)
	gologging.SetBackend(leveledBackend)
	SetLogLevel(SILENT)
}
コード例 #11
0
ファイル: client.go プロジェクト: skycoin/skycoin-exchange
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)
}
コード例 #12
0
ファイル: logger.go プロジェクト: kei-yamazaki/loggregator
func init() {

	Log = Logger{
		log: gologging.MustGetLogger(defaultModule),
	}
	Log.log.ExtraCalldepth = 1
	format = gologging.MustStringFormatter("%{time:2006-01-02T15:04:05.000000Z} %{shortfunc:.6s} %{level}: %{message}")
	backend := gologging.NewLogBackend(os.Stdout, "", 0)
	backendFormatter := gologging.NewBackendFormatter(backend, format)
	leveledBackend := gologging.AddModuleLevel(backendFormatter)
	backends = append(backends, leveledBackend)
	gologging.SetBackend(backends...)
	SetLevel(SILENT)
}
コード例 #13
0
func BenchmarkGologgingTextPositive(b *testing.B) {
	stream := &blackholeStream{}
	logger := log.MustGetLogger("")
	subBackend := log.NewLogBackend(stream, "", 0)
	formatter := log.MustStringFormatter("%{time:2006-01-02T15:04:05Z07:00} %{level} %{message}")
	backend := log.NewBackendFormatter(subBackend, formatter)
	leveled := log.AddModuleLevel(backend)
	logger.SetBackend(leveled)
	b.ResetTimer()

	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			logger.Info("The quick brown fox jumps over the lazy dog")
		}
	})

	if stream.WriteCount() != uint64(b.N) {
		b.Fatalf("Log write count")
	}
}
コード例 #14
0
ファイル: log.go プロジェクト: EaterOfCode/ClueGetter
func logSetupGlobal(logLevelStr string) {
	logLevel, err := logging.LogLevel(logLevelStr)
	if err != nil {
		log.Fatal("Invalid log level specified")
	}

	var formatStdout = logging.MustStringFormatter(
		"%{color}%{time:2006-01-02T15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{color:reset} %{message}",
	)
	stdout := logging.NewLogBackend(os.Stdout, "", 0)
	formatter := logging.NewBackendFormatter(stdout, formatStdout)
	stdoutLeveled := logging.AddModuleLevel(formatter)
	stdoutLeveled.SetLevel(logLevel, "")
	syslogBackend, err := logging.NewSyslogBackendPriority("cluegetter", syslog.LOG_MAIL)
	if err != nil {
		Log.Fatal(err)
	}

	logging.SetBackend(syslogBackend, stdoutLeveled)
}
コード例 #15
0
ファイル: main.go プロジェクト: 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()
}
コード例 #16
0
ファイル: log.go プロジェクト: masaki-saeki/gohan
func getLeveledBackend(out io.Writer, formatter logging.Formatter) logging.LeveledBackend {
	backend := logging.NewLogBackend(out, "", 0)
	backendFormatter := logging.NewBackendFormatter(backend, formatter)
	return logging.AddModuleLevel(backendFormatter)
}