Ejemplo n.º 1
0
func createLogger(debug bool) {
	var config log.Config
	config.Layout = log.LY_DEFAULT
	config.LayoutStyle = log.LS_DEFAULT
	config.TimeFormat = log.TF_DEFAULT
	if debug {
		config.Level = log.DEBUG
	} else {
		config.Level = log.INFO
	}

	var err error
	Logger, err = log.New(os.Stdout, config)
	if err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
		os.Exit(1)
	}
}
Ejemplo n.º 2
0
func createLogger(file string, l log.LevelType, p os.FileMode) (logger *log.Logger, err error) {
	var config log.Config
	config.Level = l
	config.TimeFormat = log.TF_DEFAULT
	config.Utc = false

	var f *os.File
	if file == "" {
		f = os.Stdout
	} else {
		f, err = log.OpenFile(file, p)
		if err != nil {
			return
		}
	}

	logger, err = log.New(f, config)
	return
}