func main() {
	c, err := NewConfigFromEnv()
	if err != nil {
		if err == ErrUsage {
			os.Exit(0)
		}

		log.Criticalf("Failed to configure the application: %s", err)
		os.Exit(1)
	}

	utils.AddSignalHandlers()

	s := NewServer(c)
	if err = s.Start(); err != nil {
		log.Criticalf("Failed to start server: %v", err)
		os.Exit(255)
	}
}
func main() {
	cm := NewConfigManager()

	if cm.Daemonize() {
		utils.Daemonize(cm.DebugLogFile(), cm.PidFile())
	}
	utils.AddSignalHandlers()
	loggo.ConfigureLoggers(cm.LogLevels())

	raddr := net.JoinHostPort(cm.DestHost(), strconv.Itoa(cm.DestPort()))
	log.Infof("Connecting to %s over %s", raddr, cm.DestProtocol())
	logger, err := syslog.Dial(cm.Hostname(), cm.DestProtocol(), raddr, cm.RootCAs(), cm.ConnectTimeout(), cm.WriteTimeout())

	if err != nil {
		log.Errorf("Cannot connect to server: %v", err)
	}

	go tailFiles(cm.Files(), cm.ExcludeFiles(), cm.ExcludePatterns(), cm.RefreshInterval(), logger, cm.Severity(), cm.Facility(), cm.Poll())

	for err = range logger.Errors {
		log.Errorf("Syslog error: %v", err)
	}
}