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

Golang log4go.NewFileLogWriter函数代码示例

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

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



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

示例1: newFileFilter

func newFileFilter(file string) *log4go.FileLogWriter {
	flw := log4go.NewFileLogWriter(file, false)
	//flw.SetFormat("[%D %T] [%L] (%S) %M")
	flw.SetFormat("[%D %T] [%L] %M")
	flw.SetRotateLines(0)
	flw.SetRotateSize(0)
	flw.SetRotateDaily(false)

	return flw
}
开发者ID:caohao2008,项目名称:goose,代码行数:10,代码来源:log.go


示例2: initLogger

func initLogger() {
	_logInstance = &GlobalLogger{TAG, make(l4g.Logger, 2)}

	consoleLogWriter := l4g.NewConsoleLogWriter()
	fileLogWriter := l4g.NewFileLogWriter(getLogFilePath(), false)
	fileLogWriter.SetFormat(LOG_FILE_FORMAT)

	_logInstance.AddFilter("stdout", l4g.DEBUG, consoleLogWriter)
	_logInstance.AddFilter("file", l4g.DEBUG, fileLogWriter)
	_logInstance.Info(TAG, "日志模块已启动。")
}
开发者ID:virtao,项目名称:globallog,代码行数:11,代码来源:globallog.go


示例3: 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:Wikia,项目名称:influxdb,代码行数:49,代码来源:influxd.go


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

		lw := l4g.NewConsoleLogWriter()
		lw.SetFormat("[%D %T] [%L] %M")
		l4g.AddFilter("stdout", level, lw)
	}

	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:ttyniwa,项目名称:platform,代码行数:43,代码来源:config.go


示例5: getLogWithFileName

func (logManager *LogManager) getLogWithFileName(filePath string) log4go.Logger {
	logger, ok := logManager.loggerMap[filePath]
	if ok {
		return logger
	} else {
		// Create the empty logger
		logger := make(log4go.Logger)
		fileWriter := log4go.NewFileLogWriter(filePath, false)
		fileWriter.SetFormat("[%D %T] [%L] (%S) %M")
		fileWriter.SetRotate(false)
		fileWriter.SetRotateSize(100 * 1024 * 1024)
		fileWriter.SetRotateLines(0)
		fileWriter.SetRotateDaily(false)
		logger.AddFilter("file", log4go.DEBUG, fileWriter)

		logManager.loggerMap[filePath] = logger
		return logger
	}
}
开发者ID:cloudawan,项目名称:cloudone_utility,代码行数:19,代码来源:logger.go


示例6: LogTo

func LogTo(target string, level_name 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 {
		var level = log.DEBUG

		switch level_name {
		case "FINEST":
			level = log.FINEST
		case "FINE":
			level = log.FINE
		case "DEBUG":
			level = log.DEBUG
		case "TRACE":
			level = log.TRACE
		case "INFO":
			level = log.INFO
		case "WARNING":
			level = log.WARNING
		case "ERROR":
			level = log.ERROR
		case "CRITICAL":
			level = log.CRITICAL
		default:
			level = log.DEBUG
		}

		root.AddFilter("log", level, writer)
	}
}
开发者ID:GuoJianghui,项目名称:ngrok,代码行数:39,代码来源:logger.go


示例7: handle

func handle(w http.ResponseWriter, r *http.Request) {

	folderPath, _ := osext.ExecutableFolder()

	/*
	   Preparing Logging
	*/
	log := l4g.NewLogger()
	flw := l4g.NewFileLogWriter(folderPath+LogFileName, false)
	clw := l4g.NewConsoleLogWriter()

	flw.SetFormat("[%D %T] [%L] (%S) %M")
	log.AddFilter("file", l4g.FINE, flw)
	log.AddFilter("stdout", l4g.FINE, clw)

	var items []LogRecord

	/*
	   Error cecking, data validation
	*/
	if r.Method != "POST" {
		w.WriteHeader(http.StatusMethodNotAllowed)
		fmt.Fprintf(w, "%s", "Cotnact admin!\n")
		log.Error("Method Not Allowed: %s", r.Method)
		return
	}

	if r.ParseForm() != nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprintf(w, "%s", "Cotnact admin!\n")
		log.Error("Parse POST data failed!")
		return
	}

	if r.FormValue("postdata") == "" {
		w.WriteHeader(http.StatusExpectationFailed)
		fmt.Fprintf(w, "%s", "POST Data missing!\n")
		log.Error("POST Data missing")
		return
	}

	/*
	   Deciding file name
	*/
	const timeformat = "2006-01-02_15-04-05"
	var filename = time.Now().Format(timeformat) + ".log"
	if r.FormValue("username") != "" {
		filename = r.FormValue("username") + "_" + time.Now().Format(timeformat) + ".log"
	}

	/*
	   Json Parsing and data validation
	*/
	json.Unmarshal([]byte(r.FormValue("postdata")), &items)
	if len(items) == 0 {
		w.WriteHeader(http.StatusExpectationFailed)
		log.Error("Possible Json Parse Error: Nr of items: %d ", len(items))
		fmt.Fprintf(w, "Possible Json Parse Error: Nr of items: %d ", len(items))
		return
	}

	filebuffer := ""
	for _, item := range items {
		b, err := json.Marshal(item)
		if err != nil {
			log.Error("Json Parse Error: %s ", err)
		}
		filebuffer += string(b) + "\n"
	}

	log.Info("writing %d items to %s", len(items), filename)

	/*
	   File Creation
	*/
	f, err := os.Create(os.Args[2] + filename)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Error("File create error (%s): %s ", filename, err)
		return

	}
	/*
	   File Write
	*/
	_, err = io.WriteString(f, filebuffer)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Error("File write error (%s): %s ", filename, err)
		return

	}
	f.Close()

	m := email.NewMessage("Socialeyes feedback", "The feedback file is attached!")
	m.From = "[email protected]"
	m.To = []string{"[email protected]", "[email protected]"}
	error := m.Attach(os.Args[2] + filename)
	if error != nil {
		log.Info("Successfully sent notification mail.")
//.........这里部分代码省略.........
开发者ID:uguratar,项目名称:Echelon,代码行数:101,代码来源:echelon.go


示例8: main

func main() {
	log4go.AddFilter("stdout", log4go.FINE, log4go.NewConsoleLogWriter())
	log4go.AddFilter("filelog", log4go.FINE, log4go.NewFileLogWriter("beginner.log", false))

	route.Run()
}
开发者ID:varding,项目名称:beginner,代码行数:6,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang log4go.Warn函数代码示例发布时间: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