func level3() { rlog.Error("nested function call") }
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") }