@@ -73,7 +73,7 @@ void WriteLog(const TString& log, const TVector<THolder<TLogBackend>>& logBacken
7373 log.length ()
7474 ));
7575 } catch (const yexception& e) {
76- LOG_W (" WriteLog: unable to write audit log (error: " << e.what () << " )" );
76+ LOG_E (" WriteLog: unable to write audit log (error: " << e.what () << " )" );
7777 }
7878 }
7979}
@@ -91,6 +91,27 @@ TString GetJsonLog(const TEvAuditLog::TEvWriteAuditLog::TPtr& ev) {
9191 return ss.Str ();
9292}
9393
94+ TString GetJsonLogCompatibleLog (const TEvAuditLog::TEvWriteAuditLog::TPtr& ev) {
95+ const auto * msg = ev->Get ();
96+ TStringStream ss;
97+ NJsonWriter::TBuf json (NJsonWriter::HEM_DONT_ESCAPE_HTML, &ss);
98+ {
99+ auto obj = json.BeginObject ();
100+ obj
101+ .WriteKey (" @timestamp" )
102+ .WriteString (msg->Time .ToString ().data ())
103+ .WriteKey (" @log_type" )
104+ .WriteString (" audit" );
105+
106+ for (auto & [k, v] : msg->Parts ) {
107+ obj.WriteKey (k).WriteString (v);
108+ }
109+ json.EndObject ();
110+ }
111+ ss << Endl;
112+ return ss.Str ();
113+ }
114+
94115TString GetTxtLog (const TEvAuditLog::TEvWriteAuditLog::TPtr& ev) {
95116 const auto * msg = ev->Get ();
96117 TStringStream ss;
@@ -146,6 +167,9 @@ class TAuditLogActor final : public TActor<TAuditLogActor> {
146167 case NKikimrConfig::TAuditConfig::TXT:
147168 WriteLog (GetTxtLog (ev), logBackends.second );
148169 break ;
170+ case NKikimrConfig::TAuditConfig::JSON_LOG_COMPATIBLE:
171+ WriteLog (GetJsonLogCompatibleLog (ev), logBackends.second );
172+ break ;
149173 default :
150174 WriteLog (GetJsonLog (ev), logBackends.second );
151175 break ;
0 commit comments