Exemplo n.º 1
0
func configureLog() error {
	var err error
	log, err = logging.GetLogger("notifier")
	if err != nil {
		return fmt.Errorf("Can't initialize logger: %s", err.Error())
	}

	var logBackend *logging.LogBackend

	logLevel, err := logging.LogLevel(config.Get("notifier", "log_level"))
	if err != nil {
		logLevel = logging.DEBUG
	}
	logging.SetFormatter(logging.MustStringFormatter("%{time:2006-01-02 15:04:05}\t%{level}\t%{message}"))
	logFileName := config.Get("notifier", "log_file")
	if logFileName == "stdout" || logFileName == "" {
		logBackend = logging.NewLogBackend(os.Stdout, "", 0)
	} else {
		logDir := filepath.Dir(logFileName)
		if err := os.MkdirAll(logDir, 755); err != nil {
			return fmt.Errorf("Can't create log directories %s: %s", logDir, err.Error())
		}
		logFile, err := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
		if err != nil {
			return fmt.Errorf("Can't open log file %s: %s", logFileName, err.Error())
		}
		logBackend = logging.NewLogBackend(logFile, "", 0)
	}
	logBackend.Color = (config.Get("notifier", "log_color") == "true")
	logging.SetBackend(logBackend)
	logging.SetLevel(logLevel, "notifier")

	notifier.SetLogger(log)

	return nil
}
Exemplo n.º 2
0
	RegisterFailHandler(Fail)
	if *tcReport {
		RunSpecsWithCustomReporters(t, "Notifier Suite", []Reporter{reporters.NewTeamCityReporter(os.Stdout)})
	} else {
		RunSpecs(t, "Notifier Suite")
	}
}

var _ = Describe("Notifier", func() {
	var err error
	var event notifier.EventData

	BeforeSuite(func() {
		log, _ = logging.GetLogger("notifier")
		notifier.SetLogger(log)
		testConfig.dict["notifier"] = make(map[string]string)
		testConfig.dict["notifier"]["sender_timeout"] = "0s10ms"
		testConfig.dict["notifier"]["resending_timeout"] = "24:00"
		notifier.SetSettings(testConfig)
		logging.SetFormatter(logging.MustStringFormatter("%{time:2006-01-02 15:04:05}\t%{level}\t%{message}"))
		logBackend := logging.NewLogBackend(os.Stdout, "", 0)
		logBackend.Color = false
		logging.SetBackend(logBackend)
		logging.SetLevel(logging.DEBUG, "notifier")
		now := notifier.GetNow()
		log.Debug("Using now time: %s, %s", now, now.Weekday())
	})

	AfterEach(func() {
		stopSenders()