Example #1
0
func init() {
	log.Formatter = new(logrus.JSONFormatter)
	tmp := new(logrus.TextFormatter) // default
	tmp.ForceUnColored = false
	tmp.DisableTimestamp = true
	log.Formatter = tmp
	log.Level = logrus.DebugLevel
	tmp2 := new(logrus.TextFormatter) // default
	tmp2.ForceUnColored = true
	tmp2.DisableTimestamp = true
	log.Hooks.Add(lfshook.NewHook(lfshook.PathMap{
		logrus.InfoLevel:  "log.log",
		logrus.ErrorLevel: "log.log",
		logrus.DebugLevel: "log.log",
		logrus.PanicLevel: "log.log",
		logrus.FatalLevel: "log.log",
		logrus.WarnLevel:  "log.log",
	}, new(logrus.JSONFormatter)))
}
Example #2
0
func init() {
	// Parse flags
	flag.Parse()
	// open config
	conf = et.ParseConfig(*configFile)
	// Init log system
	log = logrus.New()
	log.Formatter = new(logrus.TextFormatter)
	// Init log to file
	switch conf.Main.Log_file_formatter {
	case "json":
		log.Hooks.Add(lfshook.NewHook(lfshook.PathMap{
			logrus.InfoLevel:  conf.Main.Log_file,
			logrus.ErrorLevel: conf.Main.Log_file,
			logrus.DebugLevel: conf.Main.Log_file,
			logrus.PanicLevel: conf.Main.Log_file,
			logrus.FatalLevel: conf.Main.Log_file,
			logrus.WarnLevel:  conf.Main.Log_file,
		}, new(logrus.JSONFormatter)))
	case "text":
		formatter := new(logrus.TextFormatter) // default
		formatter.ForceUnColored = true
		log.Hooks.Add(lfshook.NewHook(lfshook.PathMap{
			logrus.InfoLevel:  conf.Main.Log_file,
			logrus.ErrorLevel: conf.Main.Log_file,
			logrus.DebugLevel: conf.Main.Log_file,
			logrus.PanicLevel: conf.Main.Log_file,
			logrus.FatalLevel: conf.Main.Log_file,
			logrus.WarnLevel:  conf.Main.Log_file,
		}, formatter))
	default:
		log.WithFields(logrus.Fields{
			"module": "front",
		}).Fatalln("Unrecognized log file formatter:", conf.Main.Log_file_formatter)
	}
	switch conf.Main.Log_level {
	case "debug":
		log.Level = logrus.DebugLevel
	case "info":
		log.Level = logrus.InfoLevel
	case "warn":
		log.Level = logrus.WarnLevel
	case "error":
		log.Level = logrus.ErrorLevel
	case "fatal":
		log.Level = logrus.FatalLevel
	case "panic":
		log.Level = logrus.PanicLevel
	default:
		log.WithFields(logrus.Fields{
			"module": "front",
		}).Fatalln("Unrecognized log level:", conf.Main.Log_level)
	}
	if !conf.Front.Enabled {
		log.WithFields(logrus.Fields{
			"module": "front",
		}).Fatalln("Front service is not enabled.")
	}
	log.WithFields(logrus.Fields{
		"module": "front",
	}).Infoln("Front service initialization complete.")
}
Example #3
0
func init() {
	// Parse flags
	flag.Parse()
	// open config
	conf = et.ParseConfig(*configFile)
	// Init log system
	log = logrus.New()
	log.Formatter = new(logrus.TextFormatter)
	// Init log to file
	switch conf.Main.Log_file_formatter {
	case "json":
		log.Hooks.Add(lfshook.NewHook(lfshook.PathMap{
			logrus.InfoLevel:  conf.Main.Log_file,
			logrus.ErrorLevel: conf.Main.Log_file,
			logrus.DebugLevel: conf.Main.Log_file,
			logrus.PanicLevel: conf.Main.Log_file,
			logrus.FatalLevel: conf.Main.Log_file,
			logrus.WarnLevel:  conf.Main.Log_file,
		}, new(logrus.JSONFormatter)))
	case "text":
		formatter := new(logrus.TextFormatter) // default
		formatter.ForceUnColored = true
		log.Hooks.Add(lfshook.NewHook(lfshook.PathMap{
			logrus.InfoLevel:  conf.Main.Log_file,
			logrus.ErrorLevel: conf.Main.Log_file,
			logrus.DebugLevel: conf.Main.Log_file,
			logrus.PanicLevel: conf.Main.Log_file,
			logrus.FatalLevel: conf.Main.Log_file,
			logrus.WarnLevel:  conf.Main.Log_file,
		}, formatter))
	default:
		log.Fatalln("Unrecognized log file formatter:", conf.Main.Log_file_formatter)
	}
	switch conf.Main.Log_level {
	case "debug":
		log.Level = logrus.DebugLevel
	case "info":
		log.Level = logrus.InfoLevel
	case "warn":
		log.Level = logrus.WarnLevel
	case "error":
		log.Level = logrus.ErrorLevel
	case "fatal":
		log.Level = logrus.FatalLevel
	case "panic":
		log.Level = logrus.PanicLevel
	default:
		log.Fatalln("Unrecognized log level:", conf.Main.Log_level)
	}
	// setup backup fi.e
	safe_file, err := os.OpenFile(conf.Main.Backup_file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.WithFields(logrus.Fields{
			"module": "main",
		}).Fatalln("Failed to open backup file:", err)
	}
	fail_safe := golog.New(safe_file, "", golog.LstdFlags)
	// init avro
	avro := et.NewAvroInst(log, conf.Avro)
	// init kafka
	kafka = et.NewKafkaInst(log, conf.Kafka)
	defaultHandler = et.NewDefaultHandler(log, fail_safe, kafka, avro)
	log.WithFields(logrus.Fields{
		"module": "main",
	}).Infoln("Initialization done.")
}