本文整理汇总了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())
}
示例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))
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}