Esempio n. 1
0
// Convenience method to initialize rlog with a single (error-level) gocheck
// logger and start rlog. Can be called at the start of your test method or in
// your test setup. Remember to put "defer rlog.Flush()" either in your test
// method(s) or test teardown method. The test teardown is invoked before the
// success/failure of the gocheck test is evaluated.
func StartGoCheckLogger(c *gocheck.C) {
	rlog.ResetState()
	rlog.EnableModule(NewGoCheckLogger(c))
	rlogConf := rlog.GetDefaultConfig()
	rlogConf.Severity = rlog.SeverityError
	rlog.Start(rlogConf)
}
Esempio n. 2
0
// Convenience method to initialize rlog with a single (error-level) testing
// logger and start rlog. Remember to put "defer rlog.Flush()" somewhere in your
// test method(s).
func StartTestingLogger(t *testing.T) {
	rlog.ResetState()
	rlog.EnableModule(NewTestingLogger(t))
	rlogConf := rlog.GetDefaultConfig()
	rlogConf.Severity = rlog.SeverityError
	rlog.Start(rlogConf)
}
Esempio n. 3
0
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 =================")
}
Esempio n. 4
0
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()
}
Esempio n. 5
0
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")

}