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


Golang Logger.SetPrefix方法代码示例

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


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

func (ca *CookieAuth) SetLogger(l *log.Logger) {
	if l.Prefix() == "" {
		l.SetPrefix("[" + pkgID + "] ")
	}
	ca.mut.Lock()
	ca.logger = l
	ca.mut.Unlock()
}
开发者ID:jpillora,项目名称:cookieauth,代码行数:8,代码来源:cookieauth.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: StartWorker

func StartWorker(CacheInvalidation bool, WorkQueue chan File, log *log.Logger) {
	var err error
	for {
		select {
		case f := <-WorkQueue:
			startTime := time.Now().UTC()

			jobId := "b-" + randomString(5) + " "
			log.SetPrefix(jobId)

			log.Print("Batch process starting: " + f.Tag + ", " + f.Filename)
			// Simulate some processing time
			if f.MediaType() == "image" {
				err = f.GenerateImage(75, 75, true)
				if err != nil {
					log.Print(err)
				}
				err = f.GenerateImage(1140, 0, false)
				if err != nil {
					log.Print(err)
				}

				if CacheInvalidation {
					if err := f.Purge(); err != nil {
						log.Print(err)
					}
				}
			}
			finishTime := time.Now().UTC()
			elapsedTime := finishTime.Sub(startTime)
			log.Println("Completed in: " + elapsedTime.String())
		}
	}
}
开发者ID:denisbr,项目名称:filebin,代码行数:34,代码来源:batch.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")

	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

示例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 := 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

示例7: 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

示例8: 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

示例9: StartWorker

func StartWorker(WorkQueue chan File, log *log.Logger) {
	for {
		select {
		case f := <-WorkQueue:
			startTime := time.Now().UTC()

			jobId := "b-" + randomString(5) + " "
			log.SetPrefix(jobId)

			log.Print("Batch process starting: " + f.Tag + ", " + f.Filename)
			// Simulate some processing time
			if f.MediaType() == "image" {
				err := f.GenerateThumbnail()
				if err != nil {
					log.Print(err)
				}
			}
			finishTime := time.Now().UTC()
			elapsedTime := finishTime.Sub(startTime)
			log.Println("Completed in: " + elapsedTime.String())
		}
	}
}
开发者ID:jmcarbo,项目名称:filebin,代码行数:23,代码来源:batch.go

示例10: Test

func Test(l log.Logger) {
	l.SetPrefix("pak")
	l.Println("test from pak")
}
开发者ID:frenata,项目名称:personal,代码行数:4,代码来源:pak.go

示例11: updateLogger

func (l Logger) updateLogger(logger *log.Logger, tag string) *log.Logger {
	prefix := fmt.Sprintf("[%s] ", tag)
	logger.SetPrefix(prefix)
	return logger
}
开发者ID:UhuruSoftware,项目名称:bosh_old,代码行数:5,代码来源:logger.go

示例12: logOut

func logOut(logger *log.Logger, level string, r *http.Request, format string, v ...interface{}) {
	logger.SetPrefix(fmt.Sprintf("[%6s] %s ", level, reqID(r)))
	logger.Output(3, fmt.Sprintf(format, v...))
}
开发者ID:jamal,项目名称:flannel,代码行数:4,代码来源:log.go


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