• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log4go.NewFileLogWriter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中code/google/com/p/log4go.NewFileLogWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFileLogWriter函数的具体用法?Golang NewFileLogWriter怎么用?Golang NewFileLogWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: InitLogger

func InitLogger(logFile string, logFormat string, accessLogFile string, accessLogFormat string) {

	loglevel := l4g.INFO
	if conf.DebugMode {
		loglevel = l4g.DEBUG
	}

	log = make(l4g.Logger)
	flw := l4g.NewFileLogWriter(logFile, false)
	flw.SetFormat(logFormat)
	flw.SetRotate(false)
	flw.SetRotateSize(0)
	flw.SetRotateLines(0)
	flw.SetRotateDaily(false)
	log.AddFilter("file", loglevel, flw)

	accessLog = make(l4g.Logger)
	aflw := l4g.NewFileLogWriter(accessLogFile, false)
	aflw.SetFormat(accessLogFormat)
	aflw.SetRotate(false)
	aflw.SetRotateSize(0)
	aflw.SetRotateLines(0)
	aflw.SetRotateDaily(false)
	accessLog.AddFilter("file", loglevel, aflw)

}
开发者ID:Pereiro,项目名称:bb,代码行数:26,代码来源:log.go


示例2: Init

/*
Init - initialize log lib

RETURNS:
    *Logger, nil - if succeed
    nil, error   - if fail
*/
func (l *Logger) Init() (*Logger, error) {
	// check, and create dir if nonexist
	if err := logDirCreate(l.logDir); err != nil {
		return nil, err
	}

	// default level: INFO
	level := log4go.INFO
	if l.enableDebug {
		level = log4go.DEBUG
	}

	// set logger format
	logFormat := func(enableDebug bool) string {
		if enableDebug {
			return log4go.FORMAT_DEFAULT
		}
		return FORMAT_WITHOUT_SRC
	}(l.enableDebug)

	// create logger
	logger := make(log4go.Logger)

	// create writer for stdout
	if l.enableStdout {
		logger.AddFilter("stdout", level, log4go.NewConsoleLogWriter())
	}

	// create file writer for all log
	fileName := filenameGen(l.progName, l.logDir, false)
	logWriter := log4go.NewFileLogWriter(fileName, l.enableRotate)
	if l.enableRotate {
		logWriter.SetRotateSize(l.rotateSize)
		logWriter.SetRotateDaily(true)
	}
	logWriter.SetFormat(logFormat)
	logger.AddFilter("log", level, logWriter)

	if l.enableWf {
		fileNameWf := filenameGen(l.progName, l.logDir, true)
		logWriterWf := log4go.NewFileLogWriter(fileNameWf, l.enableRotate)
		if l.enableRotate {
			logWriterWf.SetRotateSize(l.rotateSize)
			logWriterWf.SetRotateDaily(true)
		}
		logWriterWf.SetFormat(logFormat)
		logger.AddFilter("log_wf", log4go.WARNING, logWriterWf)
	}

	// set Logger
	l.Logger = logger

	return l, nil
}
开发者ID:beanbee,项目名称:log-go,代码行数:61,代码来源:log.go


示例3: GetLogger

func GetLogger(path string, level string) *Log {
	var log Log

	if path == "" {
		path = DEFAULT_LOG_PATH
	}

	lv := log4go.ERROR
	switch level {
	case "debug":
		lv = log4go.DEBUG
	case "error":
		lv = log4go.ERROR
	case "info":
		lv = log4go.INFO
	}

	l := log4go.NewDefaultLogger(lv)
	//l.AddFilter("log", lv, log4go.NewFileLogWriter(path, true))
	l.AddFilter("log", lv, log4go.NewFileLogWriter(path, false))

	log.l = l

	return &log
}
开发者ID:wxjs33,项目名称:kfkcp,代码行数:25,代码来源:log.go


示例4: setupLogging

func setupLogging(loggingLevel, logFile string) {
	level := log.DEBUG
	switch loggingLevel {
	case "info":
		level = log.INFO
	case "warn":
		level = log.WARNING
	case "error":
		level = log.ERROR
	}

	for _, filter := range log.Global {
		filter.Level = level
	}

	if logFile == "stdout" {
		log.AddFilter("stdout", level, log.NewConsoleLogWriter())
	} else {
		logDir := filepath.Dir(logFile)
		if err := os.MkdirAll(logDir, 0744); err != nil {
			panic(err)
		}

		writer := log.NewFileLogWriter(logFile, false)
		log.AddFilter("file", level, writer)
		writer.SetFormat("[%D %t] [%L] (%S) %M")
		writer.SetRotate(true)
		writer.SetRotateSize(0)
		writer.SetRotateLines(0)
		writer.SetRotateDaily(true)
	}
}
开发者ID:jlyt898,项目名称:fae,代码行数:32,代码来源:option.go


示例5: main

func main() {
	flag.Parse()

	log4go.AddFilter("file", log4go.FINEST, log4go.NewFileLogWriter("debug.log", *rotateLog))
	defer func() {
		py.NewLock()
		py.Finalize()
	}()

	if err := termbox.Init(); err != nil {
		log4go.Exit(err)
	}
	defer func() {
		termbox.Close()
		log4go.Debug(util.Prof)
		if err := recover(); err != nil {
			log4go.Crash(err)
		}
	}()

	var t tbfe
	t.dorender = make(chan bool, render_chan_len)
	t.layout = make(map[*backend.View]layout)
	t.loop()
}
开发者ID:ochz,项目名称:lime,代码行数:25,代码来源:main.go


示例6: main

func main() {

	// Set the static directory for webgo
	path := os.Getenv("GOPATH")
	if path == "" {
		fmt.Println("GOPATH NOT SET")
		return
	}
	filepath := fmt.Sprintf("%s/../frontend/src/", path)
	web.Config.StaticDir = filepath

	// Setup logging
	log := make(l4g.Logger)
	// Create a default logger that is logging messages of FINE or higher
	l4g.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter("error_log.log", false))
	log.Close()

	// Setup the DB
	db.Init(path)

	// Parse command line arguments
	port := flag.Int("port", 80, "port number to start the server on")
	flag.Parse()
	url := fmt.Sprintf("0.0.0.0:%d", *port)

	// Start the server!
	serve.Routes()
	web.Run(url)
}
开发者ID:CDargis,项目名称:SecurityAdventures,代码行数:29,代码来源:main.go


示例7: setupLogging

func setupLogging(loggingLevel, logFile string) {
	level := log.DEBUG
	switch loggingLevel {
	case "info":
		level = log.INFO
	case "warn":
		level = log.WARNING
	case "error":
		level = log.ERROR
	}

	for _, filter := range log.Global {
		filter.Level = level
	}

	logFileDir := filepath.Dir(logFile)
	os.MkdirAll(logFileDir, 0744)

	flw := log.NewFileLogWriter(logFile, false)
	flw.SetFormat("[%D %T] [%L] (%S) %M")
	flw.SetRotate(true)
	flw.SetRotateSize(0)
	flw.SetRotateLines(0)
	flw.SetRotateDaily(true)
	log.AddFilter("file", level, flw)
	log.Info("Redirectoring logging to %s", logFile)
}
开发者ID:schmurfy,项目名称:influxdb,代码行数:27,代码来源:influxd.go


示例8: SetupLogging

func SetupLogging(loggingLevel, logFile string) {
	level := log.DEBUG
	switch loggingLevel {
	case "info":
		level = log.INFO
	case "warn":
		level = log.WARNING
	case "error":
		level = log.ERROR
	}

	log.Global = make(map[string]*log.Filter)
	Global = log.Global
	if logFile == "stdout" || logFile == "" {
		flw := log.NewConsoleLogWriter()
		log.AddFilter("stdout", level, flw)
	} else if logFile == "stderr" || logFile == "" {
		flw := log.NewConsoleLogWriter()
		log.AddFilter("stderr", level, flw)
	} else {
		logFileDir := filepath.Dir(logFile)
		os.MkdirAll(logFileDir, 0744)

		flw := log.NewFileLogWriter(logFile, false)
		log.AddFilter("file", level, flw)

		flw.SetFormat("[%D %T] [%L] (%S) %M")
		flw.SetRotate(true)
		flw.SetRotateSize(0)
		flw.SetRotateLines(0)
		flw.SetRotateDaily(true)
	}

	Global.Info("Redirectoring logging to %s %s", logFile, level)
}
开发者ID:kevinxusz,项目名称:momonga,代码行数:35,代码来源:logger.go


示例9: setLogOutput

func setLogOutput() {
	_, err := os.OpenFile(tywa.LOG_FILE, os.O_RDWR, 0666)
	if err != nil {
		fmt.Println("Unable to open log file. Reason: ", err)
	} else {
		log.AddFilter("file", log.FINE, log.NewFileLogWriter(tywa.LOG_FILE, false))
	}
}
开发者ID:chun337163833,项目名称:word-poker,代码行数:8,代码来源:wordpoker.go


示例10: initLogger

func initLogger() {
	logger = make(log4go.Logger)
	logger.AddFilter("stdout", log4go.INFO, log4go.NewConsoleLogWriter())

	if logFileName := configCommon("log", INFO); logFileName != "" {
		logger.AddFilter("file", log4go.INFO, log4go.NewFileLogWriter(logFileName, false).SetFormat("[%D %T][%L]%M - %S"))
	}
	logger.Info("log module initialized")
}
开发者ID:mehulsbhatt,项目名称:TunnelMonitor,代码行数:9,代码来源:log.go


示例11: NewAgent

func NewAgent(opts Options) *Agent {
	log := l4g.NewLogger()
	log.AddFilter("file", l4g.DEBUG, l4g.NewFileLogWriter("agent.log", false))
	return &Agent{
		opts:      opts,
		exitChan:  make(chan bool),
		startTime: time.Now(),
		clients:   make(map[*Client]struct{}, opts.MaxOnlineNum),
		Logger:    log,
	}
}
开发者ID:gbember,项目名称:gf,代码行数:11,代码来源:agent.go


示例12: main

func main() {
	// Get a new logger instance
	log := l4g.NewLogger()

	// Create a default logger that is logging messages of FINE or higher
	log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false))
	log.Close()

	/* Can also specify manually via the following: (these are the defaults) */
	flw := l4g.NewFileLogWriter(filename, false)
	flw.SetFormat("[%D %T] [%L] (%S) %M")
	flw.SetRotate(false)
	flw.SetRotateSize(0)
	flw.SetRotateLines(0)
	flw.SetRotateDaily(false)
	log.AddFilter("file", l4g.FINE, flw)

	// Log some experimental messages
	log.Finest("Everything is created now (notice that I will not be printing to the file)")
	log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
	log.Critical("Time to close out!")

	// Close the log
	log.Close()

	// Print what was logged to the file (yes, I know I'm skipping error checking)
	fd, _ := os.Open(filename)
	in := bufio.NewReader(fd)
	fmt.Print("Messages logged to file were: (line numbers not included)\n")
	for lineno := 1; ; lineno++ {
		line, err := in.ReadString('\n')
		if err == io.EOF {
			break
		}
		fmt.Printf("%3d:\t%s", lineno, line)
	}
	fd.Close()

	// Remove the file so it's not lying around
	os.Remove(filename)
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:41,代码来源:FileLogWriter_Manual.go


示例13: InitLogger

func InitLogger(filename string, logFormat string) {
	log = make(l4g.Logger)

	flw := l4g.NewFileLogWriter(filename, false)
	flw.SetFormat(logFormat)
	flw.SetRotate(false)
	flw.SetRotateSize(0)
	flw.SetRotateLines(0)
	flw.SetRotateDaily(false)
	log.AddFilter("file", l4g.INFO, flw)

	//log.LoadConfiguration(filename)
}
开发者ID:Pereiro,项目名称:fstore,代码行数:13,代码来源:log.go


示例14: setupLogging

func setupLogging(loggingLevel, logFile string) {
	level := log.DEBUG
	switch loggingLevel {
	case "fine":
		level = log.FINE
	case "debug":
		level = log.DEBUG
	case "info":
		level = log.INFO
	case "warn":
		level = log.WARNING
	case "error":
		level = log.ERROR
	default:
		log.Error("Unknown log level %s. Defaulting to DEBUG", loggingLevel)
	}

	log.Global = make(map[string]*log.Filter)

	facility, ok := GetSysLogFacility(logFile)
	if ok {
		flw, err := NewSysLogWriter(facility)
		if err != nil {
			fmt.Fprintf(os.Stderr, "NewSysLogWriter: %s\n", err.Error())
			return
		}
		log.AddFilter("syslog", level, flw)
	} else if logFile == "stdout" {
		flw := log.NewConsoleLogWriter()
		log.AddFilter("stdout", level, flw)
	} else {
		logFileDir := filepath.Dir(logFile)
		os.MkdirAll(logFileDir, 0744)

		flw := log.NewFileLogWriter(logFile, false)
		if flw == nil {
			os.Exit(1)
		}
		log.AddFilter("file", level, flw)

		flw.SetFormat("[%D %T] [%L] (%S) %M")
		flw.SetRotate(true)
		flw.SetRotateSize(0)
		flw.SetRotateLines(0)
		flw.SetRotateDaily(true)
	}

	log.Info("Redirectoring logging to %s", logFile)
}
开发者ID:ericcapricorn,项目名称:influxdb,代码行数:49,代码来源:influxd.go


示例15: LogTo

func LogTo(target string, verbosity string) {
	var writer log.LogWriter = nil

	switch target {
	case "stdout":
		writer = log.NewConsoleLogWriter()
	case "none":
		// no logging
	default:
		writer = log.NewFileLogWriter(target, true)
	}

	if writer != nil {
		setupVerbosity(writer, verbosity)
	}
}
开发者ID:radiospiel,项目名称:ngrok,代码行数:16,代码来源:logger.go


示例16: LogTo

func LogTo(target string) {
	var writer log.LogWriter = nil

	switch target {
	case "stdout":
		writer = log.NewConsoleLogWriter()
	case "none":
		// no logging
	default:
		writer = log.NewFileLogWriter(target, true)
	}

	if writer != nil {
		root.AddFilter("log", log.TRACE, writer)
	}
}
开发者ID:yowenter,项目名称:http_ngrok,代码行数:16,代码来源:logger.go


示例17: main

func main() {
	log4go.AddFilter("file", log4go.FINEST, log4go.NewFileLogWriter("debug.log", true))
	defer func() {
		py.NewLock()
		py.Finalize()
	}()

	if err := termbox.Init(); err != nil {
		log4go.Exit(err)
	}

	var t tbfe
	t.dorender = make(chan bool, render_chan_len)
	t.layout = make(map[*backend.View]layout)
	go t.renderthread()
	t.loop()
}
开发者ID:richardfontana,项目名称:lime,代码行数:17,代码来源:main.go


示例18: configureLog

func configureLog(s *model.LogSettings) {

	l4g.Close()

	if s.EnableConsole {
		level := l4g.DEBUG
		if s.ConsoleLevel == "INFO" {
			level = l4g.INFO
		} else if s.ConsoleLevel == "WARN" {
			level = l4g.WARNING
		} else if s.ConsoleLevel == "ERROR" {
			level = l4g.ERROR
		}

		l4g.AddFilter("stdout", level, l4g.NewConsoleLogWriter())
	}

	if s.EnableFile {

		var fileFormat = s.FileFormat

		if fileFormat == "" {
			fileFormat = "[%D %T] [%L] %M"
		}

		level := l4g.DEBUG
		if s.FileLevel == "INFO" {
			level = l4g.INFO
		} else if s.FileLevel == "WARN" {
			level = l4g.WARNING
		} else if s.FileLevel == "ERROR" {
			level = l4g.ERROR
		}

		flw := l4g.NewFileLogWriter(GetLogFileLocation(s.FileLocation), false)
		flw.SetFormat(fileFormat)
		flw.SetRotate(true)
		flw.SetRotateLines(LOG_ROTATE_SIZE)
		l4g.AddFilter("file", level, flw)
	}
}
开发者ID:mf1389004071,项目名称:platform,代码行数:41,代码来源:config.go


示例19: setup_logger

func setup_logger() {
	filename := "/var/log/ranger/ranger.log"

	// Create a default logger that is logging messages of FINE or higher to filename, no rotation
	//    log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false))

	// =OR= Can also specify manually via the following: (these are the defaults, this is equivalent to above)
	flw := l4g.NewFileLogWriter(filename, false)
	if flw == nil {
		fmt.Printf("No permission to write to %s, going to switch to stdout only\n", filename)
	} else {
		flw.SetFormat("[%D %T] [%L] (%S) %M")
		flw.SetRotate(false)
		flw.SetRotateSize(0)
		flw.SetRotateLines(0)
		flw.SetRotateDaily(true)
		l4g.AddFilter("file", l4g.DEBUG, flw)

		l4g.AddFilter("stdout", l4g.ERROR, l4g.NewConsoleLogWriter())
	}
}
开发者ID:pombredanne,项目名称:ranger-1,代码行数:21,代码来源:local_agent.go


示例20: main

func main() {
	screen.FillRect(nil, bgcolor)
	go ui_main()

	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////

	flw := l4g.NewFileLogWriter("/tmp/golog.log", false)
	flw.SetFormat("[%D %T] [%L] GOMANAGER : %M ")
	flw.SetRotate(false)
	flw.SetRotateSize(0)
	flw.SetRotateLines(0)
	flw.SetRotateDaily(false)
	l4g.AddFilter("file", l4g.FINE, flw)
	l4g.Info(" --- START GOMANAGER ---")
	writeSDLstr(" --- START GOMANAGER ---")

	c, err := NewConsumer(*uri, *exchange, *exchangeType, *queue, *bindingKey, *consumerTag)
	if err != nil {
		log.Fatalf("%s", err)
	}

	if *lifetime > 0 {
		l4g.Info("running for %s", *lifetime)
		time.Sleep(*lifetime)
	} else {
		l4g.Info("running forever")
		writeSDLstr("running forever")
		select {}
	}

	l4g.Info("shutting down")

	if err := c.Shutdown(); err != nil {
		log.Fatalf("error during shutdown: %s", err)
	}

}
开发者ID:AlexandreBRUXELLE,项目名称:goStartDockerViaRabbitMQ,代码行数:39,代码来源:main.go



注:本文中的code/google/com/p/log4go.NewFileLogWriter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log4go.Trace函数代码示例发布时间:2022-05-24
下一篇:
Golang log4go.NewConsoleLogWriter函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap