Example #1
0
func write(log map[string]string) error {
	if logFileName != "" {
		f, err := os.OpenFile(logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, logFilePermit)
		if err != nil {
			logger.Println("Open log failed.")
			return nil
		}
		defer f.Close()

		ltsvLog := convertLTSV(log)
		if _, err = f.WriteString(ltsvLog); err != nil {
			logger.Println("Write log failed.")
		}
	}

	if fluentTag != "" {
		logger, err := fluent.New(fluent.Config{FluentPort: fluentPort, FluentHost: fluentHost})
		if err != nil {
			return err
		}
		defer logger.Close()

		error := logger.Post(fluentTag, log)
		if error != nil {
			panic(error)
		}
	}
	return nil
}
Example #2
0
func main() {
	// initialize logger
	log := logger.Logger()
	defer log.Close()
	defer log.Flush()

	// parse input parameters
	parseFlags(log)

	// check whether this is an interactive session
	isIntSess, err := svc.IsAnInteractiveSession()
	if err != nil {
		log.Warnf("Failed to determine if we are running in an interactive session: %v", err)
	}

	// isIntSess is false by default (after declaration), this fits the use
	// case that agent is running as Windows service most of times
	switch isIntSess {
	case true:
		run(log)
	case false:
		svc.Run(serviceName, &amazonSSMAgentService{log: log})
	}
}