예제 #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
파일: logging.go 프로젝트: samahee/nagflux
//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
}