From 3dd4cdb87b53d8f6e9db886d4b1a977485a4664d Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Thu, 8 Feb 2024 17:54:34 +0300
Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2?=
 =?UTF-8?q?=20EntryToPB=20=D0=B8=20EntryFromPB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 log/log.go | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/log/log.go b/log/log.go
index d95ecbed..64d47a11 100644
--- a/log/log.go
+++ b/log/log.go
@@ -59,18 +59,21 @@ func EntryToPB(entry *Entry) *pb.LogEntry {
 		Category:  entry.Category,
 		Component: entry.Component,
 		Event:     entry.Event,
-		ObjectId:  entry.ObjectID.String(),
-		CallerId:  entry.CallerID.String(),
 		Attr:      nil, //implement
 		Tags:      entry.Tags,
 	}
+	if entry.ObjectID != nil {
+		logEntry.ObjectId = entry.ObjectID.String()
+	}
+	if entry.CallerID != nil {
+		logEntry.CallerId = entry.CallerID.String()
+	}
+
 	return logEntry
 }
 
 func EntryFromPB(request *pb.LogEntry) *Entry {
-	objectID, _ := id.Parse(request.ObjectId)
-	callerID, _ := id.Parse(request.CallerId)
-	return &Entry{
+	logEntry := &Entry{
 		ID:        request.Id,
 		Timestamp: request.Timestamp.AsTime(),
 		LogLevel:  Level(request.Level),
@@ -78,11 +81,18 @@ func EntryFromPB(request *pb.LogEntry) *Entry {
 		Category:  request.Category,
 		Component: request.Component,
 		Event:     request.Event,
-		ObjectID:  objectID,
-		CallerID:  callerID,
 		Attr:      request.Attr, // todo: как с этим работать?
 		Tags:      request.Tags,
 	}
+
+	if request.ObjectId != "" {
+		logEntry.ObjectID, _ = id.Parse(request.ObjectId)
+	}
+	if request.CallerId != "" {
+		logEntry.CallerID, _ = id.Parse(request.CallerId)
+	}
+
+	return logEntry
 }
 
 func (e *Entry) ToMap() map[string]any {
-- 
GitLab