当前位置: 首页>>代码示例>>Golang>>正文


Golang Logger.SetFlags方法代码示例

本文整理汇总了Golang中log.Logger.SetFlags方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.SetFlags方法的具体用法?Golang Logger.SetFlags怎么用?Golang Logger.SetFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在log.Logger的用法示例。


在下文中一共展示了Logger.SetFlags方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AddLogger

func (m *MultiLogger) AddLogger(l *log.Logger) {
	m.loggers = append(m.loggers, l)
	//Update the just added logger to be consistent with the style of the
	//rest of the loggers.
	l.SetFlags(m.loggers[0].Flags())
	l.SetPrefix(m.loggers[0].Prefix())
}
开发者ID:zeebo,项目名称:taglog,代码行数:7,代码来源:multilogger.go

示例2: CopyLoggerTo

// CopyLoggerTo arranges for messages to be written to any log.Logger, see
// CopyStandardLogTo for details on behaviour and details
func CopyLoggerTo(name string, logger *stdLog.Logger) {
	sev, ok := severityByName(name)
	if !ok {
		panic(fmt.Sprintf("log.CopyLoggerTo(%q): unrecognized severity name", name))
	}
	// Set a log format that captures the user's file and line:
	//   d.go:23: message
	logger.SetFlags(stdLog.Lshortfile)
	logger.SetOutput(logBridge(sev))
}
开发者ID:gitter-badger,项目名称:alkasir,代码行数:12,代码来源:glog.go

示例3: getLogger

// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "stderr")
	var newlog revelLogs

	switch output {
	case "stdout":
		newlog = revelLogs{c: colors[name], w: os.Stdout}
		logger = newLogger(&newlog)
	case "stderr":
		newlog = revelLogs{c: colors[name], w: os.Stderr}
		logger = newLogger(&newlog)
	case "off":
		return newLogger(ioutil.Discard)
	default:
		if !filepath.IsAbs(output) {
			output = filepath.Join(BasePath, output)
		}

		logPath := filepath.Dir(output)
		if err := createDir(logPath); err != nil {
			log.Fatalln(err)
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	if strings.EqualFold(name, "request") {
		logger.SetFlags(0)
		return logger
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
开发者ID:revel,项目名称:revel,代码行数:53,代码来源:revel.go

示例4: getLogger

// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "stderr")

	switch output {
	case "stdout":
		logger = newLogger(os.Stdout)
	case "stderr":
		logger = newLogger(os.Stderr)
	default:
		if output == "off" {
			output = os.DevNull
		}

		dir_path := path.Dir(output)
		_, err := os.Stat(dir_path)
		if os.IsNotExist(err) {
			err = os.MkdirAll(dir_path, 0700)
			if err != nil {
				log.Fatalf("Failed to creating log directory", dir_path, ": ", err)
			}
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
开发者ID:jlujan,项目名称:revel,代码行数:47,代码来源:revel.go

示例5: getLogger

// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "stderr")
	var newlog revelLogs

	switch output {
	case "stdout":
		newlog = revelLogs{c: colors[name], w: os.Stdout}
		logger = newLogger(&newlog)
	case "stderr":
		newlog = revelLogs{c: colors[name], w: os.Stderr}
		logger = newLogger(&newlog)
	default:
		if output == "off" {
			output = os.DevNull
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
开发者ID:jemkzheng,项目名称:revel,代码行数:41,代码来源:revel.go

示例6: getLogger

// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output, err := Config.String("log." + name + ".output")
	if err != nil {
		output = "stderr"
	}

	switch output {
	case "stdout":
		logger = newLogger(os.Stdout)
	case "stderr":
		logger = newLogger(os.Stderr)
	default:
		if output == "off" {
			output = os.DevNull
		}

		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, err := Config.Int("log." + name + ".flags")
	if err == nil {
		logger.SetFlags(flags)
	}

	prefix, err := Config.String("log." + name + ".prefix")
	if err == nil {
		logger.SetPrefix(prefix)
	}

	return logger
}
开发者ID:rjmcguire,项目名称:revel,代码行数:41,代码来源:revel.go

示例7: getLogger

// Create a logger using log.* directives in app.conf plus the current settings
// on the default logger.
func getLogger(name string, original *log.Logger) *log.Logger {
	var logger *log.Logger

	// Create a logger with the requested output. (default to stderr)
	output := Config.StringDefault("log."+name+".output", "")

	switch output {
	case "":
		return original
	case "stdout":
		logger = newLogger(&marsLogs{c: colors[name], w: os.Stdout})
	case "stderr":
		logger = newLogger(&marsLogs{c: colors[name], w: os.Stderr})
	case "off":
		return DisabledLogger
	default:
		file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalln("Failed to open log file", output, ":", err)
		}
		logger = newLogger(file)
	}

	// Set the prefix / flags.
	flags, found := Config.Int("log." + name + ".flags")
	if found {
		logger.SetFlags(flags)
	}

	prefix, found := Config.String("log." + name + ".prefix")
	if found {
		logger.SetPrefix(prefix)
	}

	return logger
}
开发者ID:roblillack,项目名称:mars,代码行数:38,代码来源:revel.go


注:本文中的log.Logger.SetFlags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。