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


Golang log4go.NewConsoleLogWriter函數代碼示例

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


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

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

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

示例3: main

func main() {
	l4g.AddFilter("stdout", l4g.WARNING, l4g.NewConsoleLogWriter())

	if len(os.Args) < 2 {
		printUsage()
	} else {
		discover := goupnp.DiscoverIGD()
		if os.Args[1] == "s" {
			igd := <-discover
			status := <-igd.GetConnectionStatus()
			fmt.Printf("%+v\n", status)
		} else if os.Args[1] == "l" {
			igd := <-discover
			for portMapping := range igd.ListRedirections() {
				fmt.Println(portMapping)
			}
		} else if os.Args[1] == "a" {
			igd := <-discover
			port, _ := strconv.Atoi(os.Args[2])
			proto := goupnp.ParseProtocol(os.Args[3])
			myMapping := <-igd.AddLocalPortRedirection(uint16(port), proto)
			fmt.Printf("%+v\n", myMapping)
		} else {
			printUsage()
		}
	}

	time.Sleep(1 * time.Second)
}
開發者ID:nhelke,項目名稱:goupnpc,代碼行數:29,代碼來源:cmd.go

示例4: init

func init() {
	// Tests outside of config_test.go also require this configuration to be
	// loaded; Config tests should reset it by making this call
	loadTestConfig("test-walker.yaml")

	// For tests it's useful to see more than the default INFO
	log4go.AddFilter("stdout", log4go.DEBUG, log4go.NewConsoleLogWriter())
}
開發者ID:pombredanne,項目名稱:walker-2,代碼行數:8,代碼來源:config_test.go

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

示例6: main

func main() {
	log4go.AddFilter("file", log4go.FINEST, log4go.NewConsoleLogWriter())
	defer func() {
		py.NewLock()
		py.Finalize()
	}()

	t = &qmlfrontend{windows: make(map[*backend.Window]*frontendWindow)}
	go t.qmlBatchLoop()
	qml.Run(t.loop)
}
開發者ID:riginding,項目名稱:lime,代碼行數:11,代碼來源:main.go

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

示例8: main

func main() {
	log4go.AddFilter("file", log4go.FINEST, log4go.NewConsoleLogWriter())
	defer func() {
		py.NewLock()
		py.Finalize()
	}()

	var t tbfe
	t.dorender = make(chan bool, render_chan_len)
	t.layout = make(map[*backend.View]layout)
	t.loop()
}
開發者ID:Unverified,項目名稱:lime,代碼行數:12,代碼來源:main.go

示例9: init

// init sets the default log4go configuration and attempts to read a log4go.xml
// file if available
func init() {
	log4go.AddFilter("stdout", log4go.INFO, log4go.NewConsoleLogWriter())
	loadLog4goConfig()
	sig := make(chan os.Signal)
	signal.Notify(sig, syscall.SIGHUP)
	go func() {
		for {
			<-sig
			loadLog4goConfig()
		}
	}()
}
開發者ID:pombredanne,項目名稱:walker-2,代碼行數:14,代碼來源:log.go

示例10: main

func main() {
	log4go.AddFilter("file", log4go.FINEST, log4go.NewConsoleLogWriter())
	defer func() {
		py.NewLock()
		py.Finalize()
	}()

	var t tbfe
	t.layout = make(map[*backend.View]layout)
	t.views = make(map[*backend.View]*frontendView)
	t.loop()
}
開發者ID:uni3orns,項目名稱:lime,代碼行數:12,代碼來源:main.go

示例11: main

func main() {
	// Need to lock the OS thread as OSX GUI requires GUI stuff to run in the main thread
	runtime.LockOSThread()

	log4go.AddFilter("file", log4go.FINEST, log4go.NewConsoleLogWriter())
	defer func() {
		py.NewLock()
		py.Finalize()
	}()

	t = &qmlfrontend{windows: make(map[*backend.Window]*frontendWindow)}
	go t.qmlBatchLoop()
	qml.Run(t.loop)
}
開發者ID:EDi-nabi,項目名稱:lime,代碼行數:14,代碼來源:main.go

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

示例13: Init

/*
* Init - initialize log lib
*
* PARAMS:
*   - progName: program name. Name of log file will be progName.log
*   - levelStr: "DEBUG", "TRACE", "INFO", "WARNING", "ERROR", "CRITICAL"
*   - logDir: directory for log. It will be created if noexist
*   - hasStdOut: whether to have stdout output
*   - when:
*       "M", minute
*       "H", hour
*       "D", day
*       "MIDNIGHT", roll over at midnight
*   - backupCount: If backupCount is > 0, when rollover is done, no more than
*       backupCount files are kept - the oldest ones are deleted.
*
* RETURNS:
*   nil, if succeed
*   error, if fail
 */
func Init(progName string, levelStr string, logDir string,
	hasStdOut bool, when string, backupCount int) error {
	if initialized {
		return errors.New("Initialized Already")
	}

	/* check when   */
	/*if !log4go.WhenIsValid(when) {
	    return fmt.Errorf("invalid value of when: %s", when)
	}*/

	/* check, and create dir if nonexist    */
	if err := logDirCreate(logDir); err != nil {
		log4go.Error("Init(), in logDirCreate(%s)", logDir)
		return err
	}

	/* convert level from string to log4go level    */
	level := stringToLevel(levelStr)

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

	/* create writer for stdout */
	if hasStdOut {
		Logger.AddFilter("stdout", level, log4go.NewConsoleLogWriter())
	}

	/* create file writer for all log   */
	fileName := filenameGen(progName, logDir, false)
	logWriter := log4go.NewTimeFileLogWriter(fileName, when, backupCount)
	if logWriter == nil {
		return fmt.Errorf("error in log4go.NewTimeFileLogWriter(%s)", fileName)
	}
	logWriter.SetFormat(log4go.LogFormat)
	Logger.AddFilter("log", level, logWriter)

	/* create file writer for warning and fatal log */
	fileNameWf := filenameGen(progName, logDir, true)
	logWriter = log4go.NewTimeFileLogWriter(fileNameWf, when, backupCount)
	if logWriter == nil {
		return fmt.Errorf("error in log4go.NewTimeFileLogWriter(%s)", fileNameWf)
	}
	logWriter.SetFormat(log4go.LogFormat)
	Logger.AddFilter("log_wf", log4go.WARNING, logWriter)

	initialized = true
	return nil
}
開發者ID:qiangmzsx,項目名稱:golang,代碼行數:69,代碼來源:log.go

示例14: main

func main() {
	log := make(log4go.Logger)
	log.AddFilter("stdout", log4go.DEBUG, log4go.NewConsoleLogWriter())

	http.HandleFunc("/", helloThere)
	http.HandleFunc("/all", all)
	http.HandleFunc("/pointer", PointerExample)
	var port string
	if port = os.Getenv(PortVar); port == "" {
		port = "8080"
	}
	log.Debug("Listening at port %v\n", port)
	if err := http.ListenAndServe(":"+port, nil); err != nil {
		panic(err)
	}
}
開發者ID:rahul-kj,項目名稱:golang-hello,代碼行數:16,代碼來源:server.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.NewConsoleLogWriter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。