-
Notifications
You must be signed in to change notification settings - Fork 2
/
LogMessage.pas
60 lines (52 loc) · 1.7 KB
/
LogMessage.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
unit LogMessage;
interface
uses
System.Sysutils, System.Classes, System.DateUtils, System.JSON, WinApi.Windows;
type
TLogMessage = record
MessageType:String;
Facility:String;
Severity:String;
TimeStamp:String;
Host:String;
Process:String;
ProcessID: DWORD;
Logmessage: String;
class function Create: TLogMessage; overload; static;
class function Create(AJson: String): TLogMessage; overload; static;
end;
implementation
class function TLogMessage.Create: TLogMessage;
begin
Result.MessageType := String.Empty;
Result.Facility := String.Empty;
Result.Severity := String.Empty;
Result.TimeStamp := String.Empty;
Result.Host := String.Empty;
Result.Process := String.Empty;
Result.ProcessID := 0;
Result.LogMessage := String.Empty;
end;
class function TLogMessage.Create(AJson: String): TLogMessage;
begin
var LJson := TJSONObject.ParseJSONValue(AJson) as TJSONObject;
try
if nil <> LJson.Values['type'] then
Result.MessageType := LJson.Values['type'].Value;
if nil <> LJson.Values['facility'] then
Result.Facility := LJson.Values['facility'].Value;
if nil <> LJson.Values['severity'] then
Result.Severity := LJson.Values['severity'].Value;
if nil <> LJson.Values['timeStamp'] then
Result.TimeStamp := LJson.Values['timeStamp'].Value;
if nil <> LJson.Values['host'] then
Result.Host := LJson.Values['host'].Value;
if nil <> LJson.Values['process'] then
Result.Process := LJson.Values['process'].Value;
if nil <> LJson.Values['logMessage'] then
Result.LogMessage := LJson.Values['logMessage'].Value;
finally
LJson.Free;
end;
end;
end.