示例#1
0
//InitLogger creates a factorlog with the given min loglevel
func InitLogger(minSeverity string) {
	mutex.Lock()
	logFormatter := factorlog.NewStdFormatter(logColors + logFormat)
	targetWriter := os.Stdout
	singleLogger = factorlog.New(targetWriter, logFormatter)
	singleLogger.SetMinMaxSeverity(factorlog.StringToSeverity(minSeverity), factorlog.StringToSeverity("PANIC"))
	mutex.Unlock()
}
示例#2
0
//InitLogger Constructor.
func InitLogger(logFile, minSeverity string) {
	var logFormatter factorlog.Formatter
	var targetWriter io.Writer
	var err error
	if logFile == "" {
		logFormatter = factorlog.NewStdFormatter(logColors + logFormat)
		targetWriter = os.Stdout
	} else {
		logFormatter = factorlog.NewStdFormatter(logFormat)
		targetWriter, err = os.OpenFile(logFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
	}
	if err != nil {
		panic(err)
	}
	singleLogger = factorlog.New(targetWriter, logFormatter)
	singleLogger.SetMinMaxSeverity(factorlog.StringToSeverity(minSeverity), factorlog.StringToSeverity("PANIC"))
}
示例#3
0
//Logger Constructor.
func InitLogger(logFile, minSeverity string) {
	var logFormatter factorlog.Formatter
	var targetWriter io.Writer
	var err error
	if logFile == "" {
		logFormatter = factorlog.NewStdFormatter(logColors + logFormat)
		targetWriter = os.Stdout
	} else {
		logFormatter = factorlog.NewStdFormatter(logFormat)
		if _, err := os.Stat(logFile); err == nil {
			targetWriter, err = os.Create(logFile)
		} else {
			targetWriter, err = os.Open(logFile)
		}
	}
	if err != nil {
		panic(err)
	}
	singleLogger = factorlog.New(targetWriter, logFormatter)
	singleLogger.SetMinMaxSeverity(factorlog.StringToSeverity(minSeverity), factorlog.StringToSeverity("PANIC"))
}
示例#4
0
//DecodeLogMessages converts the LogMessages from the JSON object to LogServer.LogMessages
func (moduleResult Result) DecodeLogMessages() *[]*LogServer.LogMessage {
	result := []*LogServer.LogMessage{}
	for _, message := range moduleResult.Messages {
		level := factorlog.StringToSeverity(strings.ToUpper(message.Severity))
		var timestamp time.Time

		if newTime, err := time.Parse(TimeParseLayout, message.Timestamp); err == nil {
			timestamp = newTime
		} else {
			timestamp = time.Now()
		}

		result = append(result, &LogServer.LogMessage{
			Timestamp: timestamp,
			Source:    message.Source,
			Severity:  level,
			Message:   message.Message,
		})
	}
	return &result
}