示例#1
0
文件: add.go 项目: toxer/log4all
/*
	Convert a RawLog to models.Log
*/
func NewLogFromRawLog(rawLog *commonsLog.SingleLog) *models.Log {
	logResult := new(models.Log)
	logResult.Tags = make(map[string]interface{})
	logResult.Level = rawLog.Level
	logResult.Application = rawLog.Application
	logResult.Stack = rawLog.Stack
	//add dtInsert if is missing
	if rawLog.Date != 0 {
		logResult.Date = time.Unix(rawLog.Date/1000, 0)
	} else {
		logResult.Date = time.Now()
	}
	//extract tags from message
	rawTags := utils.AddLogMatcher().FindAllStringSubmatch(rawLog.Message, -1)
	for i := 0; i < len(rawTags); i++ {
		tagName := rawTags[i][1][1:]
		if len(rawTags[i][4]) > 0 {
			tagValue := rawTags[i][4]
			logResult.Tags[tagName] = strings.Replace(tagValue, "\"", "", -1)
		} else {
			logResult.Tags[tagName] = true
		}
	}

	//arrange message
	logResult.Message = strings.Replace(rawLog.Message, "##", "", -1)
	logResult.Message = utils.AddLogMatcher().ReplaceAllString(logResult.Message, "")

	return logResult
}
示例#2
0
文件: add.go 项目: toxer/log4all
func (ctrl ApiLog) dbAdd(logToAdd *models.Log, writeSafe bool) error {
	// add stack
	if logToAdd.Stack != "" {
		stack := &models.Stack{Stacktrace: logToAdd.Stack}
		stack.Save(ctrl.Db)
		logToAdd.StackSha = stack.Sha
	}

	//add Log
	err := logToAdd.Save(ctrl.Db, writeSafe)
	if err != nil {
		return errors.New("Cannot insert log " + err.Error())
	} else {
		go addTags(ctrl.Db, logToAdd)
		return nil
	}
}