func (l *LogMessage) UnmarshalJSON(data []byte) error {
	var j map[string]interface{}
	if err := json.Unmarshal(data, &j); err != nil {
		return fmt.Errorf("LogMessage.UnmarshalJSON: can't unmarshal json: %s", err)
	}

	var typ string
	var ok bool

	// type

	if typ, ok = j["type"].(string); !ok {
		return fmt.Errorf("LogMessage.UnmarshalJSON: malformed log message")
	}

	// time

	if timeStr, ok := j["time"].(string); ok {
		if time, err := time.Parse(logMessageTimeLayout, timeStr); err == nil {
			l.Time = time
		}
	}

	// the rest

	switch typ {
	case LogTypePlatformLogsSubscription, LogTypePlatformExtension:
		l.Type = typ
	case LogTypeFunction, LogTypeExtension:
		l.Type = typ
		l.StringRecord = j["record"].(string)
	case LogTypePlatformStart, LogTypePlatformEnd, LogTypePlatformReport:
		l.Type = typ
		if objectRecord, ok := j["record"].(map[string]interface{}); ok {
			// all of these have the requestId
			if requestID, ok := objectRecord["requestId"].(string); ok {
				l.ObjectRecord.RequestID = requestID
			}

			switch typ {
			case LogTypePlatformStart:
				if version, ok := objectRecord["version"].(string); ok {
					l.ObjectRecord.Version = version
				}
				l.StringRecord = fmt.Sprintf("START RequestId: %s Version: %s",
					l.ObjectRecord.RequestID,
					l.ObjectRecord.Version,
				)
			case LogTypePlatformEnd:
				l.StringRecord = fmt.Sprintf("END RequestId: %s",
					l.ObjectRecord.RequestID,
				)
			case LogTypePlatformReport:
				if metrics, ok := objectRecord["metrics"].(map[string]interface{}); ok {
					if v, ok := metrics["durationMs"].(float64); ok {
						l.ObjectRecord.Metrics.DurationMs = v
					}
					if v, ok := metrics["billedDurationMs"].(float64); ok {
						l.ObjectRecord.Metrics.BilledDurationMs = int(v)
					}
					if v, ok := metrics["memorySizeMB"].(float64); ok {
						l.ObjectRecord.Metrics.MemorySizeMB = int(v)
					}
					if v, ok := metrics["maxMemoryUsedMB"].(float64); ok {
						l.ObjectRecord.Metrics.MaxMemoryUsedMB = int(v)
					}
					if v, ok := metrics["initDurationMs"].(float64); ok {
						l.ObjectRecord.Metrics.InitDurationMs = v
					}
					log.Debugf("Enhanced metrics: %+v\n", l.ObjectRecord.Metrics)
				} else {
					log.Error("LogMessage.UnmarshalJSON: can't read the metrics object")
				}
				l.StringRecord = createStringRecordForReportLog(l)
			}
		} else {
			log.Error("LogMessage.UnmarshalJSON: can't read the record object")
		}
	default:
		// we're not parsing this kind of message yet
	}

	return nil
}
// UnmarshalJSON unmarshals the given bytes in a LogMessage object.
UnmarshalJSON unmarshals the given bytes in a LogMessage object.
// UnmarshalJSON unmarshals the given bytes in a LogMessage object .
func (l *LogMessage) UnmarshalJSON(data []byte) error {
	var j map[string]interface{}
	if err := json.Unmarshal(data, &j); err != nil {
		return fmt.Errorf("LogMessage.UnmarshalJSON: can't unmarshal json: %s", err)
	}
	var typ string
	var ok bool
	if typ, ok = j["type"].(string); !ok {
		return fmt.Errorf("LogMessage.UnmarshalJSON: malformed log message")
	}
	if timeStr, ok := j["time"].(string); ok {
		if time, err := time.Parse(logMessageTimeLayout, timeStr); err == nil {
			l.Time = time
		}
	}
	switch typ {
	case LogTypePlatformLogsSubscription, LogTypePlatformExtension:
		l.Type = typ
	case LogTypeFunction, LogTypeExtension:
		l.Type = typ
		l.StringRecord = j["record"].(string)
	case LogTypePlatformStart, LogTypePlatformEnd, LogTypePlatformReport:
		l.Type = typ
		if objectRecord, ok := j["record"].(map[string]interface{}); ok {
			if requestID, ok := objectRecord["requestId"].(string); ok {
				l.ObjectRecord.RequestID = requestID
			}
			switch typ {
			case LogTypePlatformStart:
				if version, ok := objectRecord["version"].(string); ok {
					l.ObjectRecord.Version = version
				}
				l.StringRecord = fmt.Sprintf("START RequestId: %s Version: %s",
					l.ObjectRecord.RequestID,
					l.ObjectRecord.Version,
				)
			case LogTypePlatformEnd:
				l.StringRecord = fmt.Sprintf("END RequestId: %s",
					l.ObjectRecord.RequestID,
				)
			case LogTypePlatformReport:
				if metrics, ok := objectRecord["metrics"].(map[string]interface{}); ok {
					if v, ok := metrics["durationMs"].(float64); ok {
						l.ObjectRecord.Metrics.DurationMs = v
					}
					if v, ok := metrics["billedDurationMs"].(float64); ok {
						l.ObjectRecord.Metrics.BilledDurationMs = int(v)
					}
					if v, ok := metrics["memorySizeMB"].(float64); ok {
						l.ObjectRecord.Metrics.MemorySizeMB = int(v)
					}
					if v, ok := metrics["maxMemoryUsedMB"].(float64); ok {
						l.ObjectRecord.Metrics.MaxMemoryUsedMB = int(v)
					}
					if v, ok := metrics["initDurationMs"].(float64); ok {
						l.ObjectRecord.Metrics.InitDurationMs = v
					}
					log.Debugf("Enhanced metrics: %+v\n", l.ObjectRecord.Metrics)
				} else {
					log.Error("LogMessage.UnmarshalJSON: can't read the metrics object")
				}
				l.StringRecord = createStringRecordForReportLog(l)
			}
		} else {
			log.Error("LogMessage.UnmarshalJSON: can't read the record object")
		}
	default:
	}
	return nil
}
func ( l * LogMessage ) UnmarshalJSON ( data [ ] byte ) error { var j map [ string ] interface { } if err := json . Unmarshal ( data , & j ) ; err != nil { return fmt . Errorf ( " " , err ) } var typ string var ok bool if typ , ok = j [ " " ] . ( string ) ; ! ok { return fmt . Errorf ( " " ) } if timeStr , ok := j [ " " ] . ( string ) ; ok { if time , err := time . Parse ( logMessageTimeLayout , timeStr ) ; err == nil { l . Time = time } } switch typ { case LogTypePlatformLogsSubscription , LogTypePlatformExtension : l . Type = typ case LogTypeFunction , LogTypeExtension : l . Type = typ l . StringRecord = j [ " " ] . ( string ) case LogTypePlatformStart , LogTypePlatformEnd , LogTypePlatformReport : l . Type = typ if objectRecord , ok := j [ " " ] . ( map [ string ] interface { } ) ; ok { if requestID , ok := objectRecord [ " " ] . ( string ) ; ok { l . ObjectRecord . RequestID = requestID } switch typ { case LogTypePlatformStart : if version , ok := objectRecord [ " " ] . ( string ) ; ok { l . ObjectRecord . Version = version } l . StringRecord = fmt . Sprintf ( " " , l . ObjectRecord . RequestID , l . ObjectRecord . Version , ) case LogTypePlatformEnd : l . StringRecord = fmt . Sprintf ( " " , l . ObjectRecord . RequestID , ) case LogTypePlatformReport : if metrics , ok := objectRecord [ " " ] . ( map [ string ] interface { } ) ; ok { if v , ok := metrics [ " " ] . ( float64 ) ; ok { l . ObjectRecord . Metrics . DurationMs = v } if v , ok := metrics [ " " ] . ( float64 ) ; ok { l . ObjectRecord . Metrics . BilledDurationMs = int ( v ) } if v , ok := metrics [ " " ] . ( float64 ) ; ok { l . ObjectRecord . Metrics . MemorySizeMB = int ( v ) } if v , ok := metrics [ " " ] . ( float64 ) ; ok { l . ObjectRecord . Metrics . MaxMemoryUsedMB = int ( v ) } if v , ok := metrics [ " " ] . ( float64 ) ; ok { l . ObjectRecord . Metrics . InitDurationMs = v } log . Debugf ( " \n " , l . ObjectRecord . Metrics ) } else { log . Error ( " " ) } l . StringRecord = createStringRecordForReportLog ( l ) } } else { log . Error ( " " ) } default : } return nil }
UnmarshalJSON unmarshals the given bytes in a LogMessage object.
UnmarshalJSON unmarshals the given bytes in a LogMessage object .
// type // time // the rest // all of these have the requestId // we're not parsing this kind of message yet