當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log4go.NewFileLogWriter函數代碼示例

本文整理匯總了Golang中code/google/com/p/log4go.NewFileLogWriter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFileLogWriter函數的具體用法?Golang NewFileLogWriter怎麽用?Golang NewFileLogWriter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewFileLogWriter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的code/google/com/p/log4go.NewFileLogWriter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。