コード例 #1
0
ファイル: logObjects.go プロジェクト: rightscale/rlog
func main() {
	rlog.EnableModule(console.NewStdoutLogger(true))
	rlog.Start(rlog.GetDefaultConfig())
	defer rlog.Flush()

	rlog.Info("================= Rlog log objects test permutations =================")

	//Create log object
	logger := rlog.NewLogger()

	//Test all the different log levels
	logger.Debug("debug log entry")
	logger.Info("info log entry")
	logger.Error("error log entry")
	logger.Fatal("fatal log entry")

	//Generate an ID
	logger.Info("ID 1: %s", logger.GenerateID())
	logger.Info("ID 2: %s", logger.GenerateID())

	//A deeply nested stack trace
	rlog.Info("------------- Testing stack trace --------------")
	level1()

	//All done
	rlog.Info("================= Test permutations completed =================")
}
コード例 #2
0
ファイル: tags.go プロジェクト: rightscale/rlog
func main() {

	const TAG1 string = "tag1"
	const TAG2 string = "tags"

	rlog.EnableModule(console.NewStdoutLogger(true))
	conf := rlog.GetDefaultConfig()
	conf.DisableTagsExcept([]string{TAG1})
	rlog.Start(conf)

	rlog.InfoT(TAG1, "This msg should appear")
	rlog.InfoT(TAG2, "This msg should NOT appear")

	defer rlog.Flush()
}
コード例 #3
0
ファイル: modules.go プロジェクト: rightscale/rlog
func main() {

	//Setup syslog module
	facility, err := syslog.FacilityNameToValue("local6")
	if err != nil {
		panic("Getting syslog facility value failed: " + err.Error())
	}

	syslogModule, err := syslog.NewLocalFacilitySyslogLogger("", "", facility, "tmp/sysloggerHeartbeat.txt")
	if err != nil {
		panic("Getting syslog logger instance failed: " + err.Error())
	}

	//Setup file logger
	log_file_name := "tmp/test.txt"
	rotated_log_name := log_file_name + ".1"
	if _, err = os.Stat(rotated_log_name); err == nil {
		os.Remove(rotated_log_name)
	}
	fileModule, err := file.NewFileLogger(log_file_name, true, true)
	if err != nil {
		panic("Getting file logger instance failed: " + err.Error())
	}

	rlog.EnableModule(syslogModule)
	rlog.EnableModule(fileModule)
	rlog.EnableModule(console.NewStdoutLogger(true))
	rlog.EnableModule(console.NewStderrLogger(true))
	conf := rlog.GetDefaultConfig()
	conf.Severity = rlog.SeverityDebug
	rlog.Start(conf)
	defer rlog.Flush()

	//Test all the different log levels
	rlog.Debug("debug log entry")
	rlog.Info("info log entry")
	rlog.Warning("warning log entry")

	// simulate log rotation followed by SIGHUP and then flush.
	err = os.Rename(log_file_name, rotated_log_name)
	if err != nil {
		panic(err)
	}
	rlog.Flush() // will reopen logs

	rlog.Error("error log entry")
	rlog.Fatal("fatal log entry")

	//Generate a couple of IDs and log it
	ids := ""
	for i := 0; i < 10; i++ {
		ids += rlog.GenerateID() + ", "
	}
	rlog.Info("IDs: %s", ids)

	//A deeply nested stack trace
	rlog.Debug("---------------------------")
	level1()
	rlog.Debug("---------------------------")

	//A very long log message
	rlog.Debug(strings.Repeat("hello rlog, ", 1000))

	//All done
	rlog.Debug("Test permutations completed")

}