Example #1
0
func TestWarning(t *testing.T) {
	log.Init(os.Stdout, os.Stdout, os.Stdout)

	log.Warn("hello world")
	log.Warn("hello", "world")
	log.Warnf("problem: %s is: %d\n", "one", 1)
}
Example #2
0
func main() {
	infoFile, err := os.OpenFile("scrapeInfoLog.txt", os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		panic(err)
	}

	errFile, err := os.OpenFile("scrapeErrorLog.txt", os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		panic(err)
	}

	warnFile, err := os.OpenFile("scrapeWarnLog.txt", os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		panic(err)
	}
	log.Init(infoFile, errFile, warnFile)

	defer infoFile.Close()
	defer errFile.Close()
	defer warnFile.Close()

	// create the new server
	s := server.NewScrapeServer()
	j := s.GetJefe()

	j.SetCycleTime(1)
	j.Start()

	log.Info("started jefe")

	// make server scrape WSJ
	rss := server.CreateSchedulableRSS(&scraper.NYTRSS{}, 10, j)
	j.AddSchedulable(rss)

	log.Info("going to start server")

	// start up the server
	http.HandleFunc("/", s.Handle())
	http.ListenAndServe(":8080", nil)
}
Example #3
0
func main() {
	infoFile, err := os.OpenFile("rateInfoLog.txt", os.O_RDWR|os.O_CREATE, 0666)
	errFile, err := os.OpenFile("rateErrorLog.txt", os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		panic(err)
	}

	defer infoFile.Close()
	defer errFile.Close()

	log.Init(infoFile, nil, errFile)

	feeds := []rssMonitor{newMonitor(&scraper.WSJRSS{}),
		newMonitor(&scraper.NYTRSS{})}

	// get whats currently in the feeds without sending an update signal
	for _, monitor := range feeds {
		monitor.didChange()
	}

	ticker := time.NewTicker(time.Duration(5) * time.Minute)

	// flip only prints the articles once every 5 minutes
	flip := false

	for {
		// wait for new ticker value
		<-ticker.C

		updateFeeds(feeds)

		if flip {
			for _, monitor := range feeds {
				log.Info("average time is: ", monitor.tracker.getAverage())
			}
		}
		flip = !flip
	}

}