Ejemplo n.º 1
0
func setUpEventlog(cfg config.Config, bus *eventbus.EventBus) {
	if len(cfg.Eventlog.Path) == 0 {
		return
	}
	eventwriter, err := rfw.Open(cfg.Eventlog.Path, cfg.Eventlog.Mode)
	if err != nil {
		log.Error("Error opening event log for writing: %s", err)
	} else {
		log.Info("Logging events to %s", cfg.Eventlog.Path)
		evtlog := eventlog.New(eventwriter)
		evtlog.Register(bus)
	}
}
Ejemplo n.º 2
0
func main() {
	args := os.Args
	if len(args) > 1 {
		loggo.ConfigureLoggers(args[1])
	} else {
		fmt.Println("Add a parameter to configure the logging:")
		fmt.Println("E.g. \"<root>=INFO;first=TRACE\"")
	}
	fmt.Println("\nCurrent logging levels:")
	fmt.Println(loggo.LoggerInfo())
	fmt.Println("")

	rootLogger.Infof("Start of test.")

	FirstCritical("first critical")
	FirstError("first error")
	FirstWarning("first warning")
	FirstInfo("first info")
	FirstTrace("first trace")

	SecondCritical("first critical")
	SecondError("first error")
	SecondWarning("first warning")
	SecondInfo("first info")
	SecondTrace("first trace")

	writer, err := rfw.Open("./myprogram", 0644)
	if err != nil {
		log.Fatalln("Could not open '/var/log/myprogram': ", err)
	}

	log := log.New(writer, "[myprogram] ", log.LstdFlags)
	log.Println("Logging as normal")

	//defaultWriter, _, err := loggo.RemoveWriter("default")

	// err is non-nil if and only if the name isn't found.
	//loggo.RegisterWriter("default", writer, loggo.TRACE)
	newWriter := loggo.NewSimpleWriter(writer, &loggo.DefaultFormatter{})
	err = loggo.RegisterWriter("testfile", newWriter, loggo.TRACE)

	now := time.Now().Nanosecond()
	fmt.Printf("CurrentTime: %d\n", now)
	FirstCritical("first critical")
	FirstError("first error")
	FirstWarning("first warning")
	FirstInfo("first info")
	FirstTrace("first trace")

	SecondCritical("first critical")
	SecondError("first error")
	SecondWarning("first warning")
	SecondInfo("first info")
	SecondTrace("first trace")

	viper.SetConfigName("config")        // name of config file (without extension)
	viper.AddConfigPath("/etc/appname/") // path to look for the config file in
	viper.AddConfigPath("$HOME/")        // call multiple times to add many search paths
	viper.ReadInConfig()                 // Find and read the config file

	title := viper.GetString("title")
	fmt.Printf("TITLE=%s\n", title)
}