1212import java .io .Serializable ;
1313import java .text .SimpleDateFormat ;
1414import java .util .Date ;
15+ import java .util .HashMap ;
16+ import java .util .Map ;
1517
1618import org .apache .commons .lang3 .StringUtils ;
1719
@@ -30,116 +32,28 @@ public class ServerLogItem implements Serializable {
3032 private String message ;
3133 private String throwableInformation ;
3234 private String channelName ;
35+ private HashMap <String , Object > context ;
3336
3437 public ServerLogItem () {}
3538
36- public ServerLogItem (String message ) {
37- this (null , null , null , null , null , null , null , null , null , message , null );
38- }
39-
40- public ServerLogItem (String serverId , Long id , String level , Date date , String threadName , String category , String lineNumber , String message , String throwableInformation ) {
41- this (serverId , id , null , null , level , date , threadName , category , lineNumber , message , throwableInformation );
42- }
43-
44- public ServerLogItem (String serverId , Long id , String channelId , String channelName , String level , Date date , String threadName , String category , String lineNumber , String message , String throwableInformation ) {
45- this .serverId = serverId ;
46- this .id = id ;
47- this .channelId = channelId ;
48- this .channelName = channelName ;
49- this .level = level ;
50- this .date = date ;
51- this .threadName = threadName ;
52- this .category = category ;
53- this .lineNumber = lineNumber ;
54- this .message = message ;
55- this .throwableInformation = throwableInformation ;
56- }
57-
58- private ServerLogItem (Builder builder ) {
59- this .serverId = builder .serverId ;
60- this .id = builder .id ;
61- this .channelId = builder .channelId ;
62- this .channelName = builder .channelName ;
63- this .level = builder .level ;
64- this .date = builder .date ;
65- this .threadName = builder .threadName ;
66- this .category = builder .category ;
67- this .lineNumber = builder .lineNumber ;
68- this .message = builder .message ;
69- this .throwableInformation = builder .throwableInformation ;
70- }
71-
72- public static class Builder {
73- private String serverId ;
74- private Long id ;
75- private String channelId ;
76- private String channelName ;
77- private String level ;
78- private Date date ;
79- private String threadName ;
80- private String category ;
81- private String lineNumber ;
82- private String message ;
83- private String throwableInformation ;
84-
85- public Builder serverId (String serverId ) {
86- this .serverId = serverId ;
87- return this ;
88- }
89-
90- public Builder id (Long id ) {
91- this .id = id ;
92- return this ;
93- }
94-
95- public Builder channelId (String channelId ) {
96- this .channelId = channelId ;
97- return this ;
98- }
99-
100- public Builder channelName (String channelName ) {
101- this .channelName = channelName ;
102- return this ;
103- }
104-
105- public Builder level (String level ) {
106- this .level = level ;
107- return this ;
108- }
109-
110- public Builder date (Date date ) {
111- this .date = date ;
112- return this ;
113- }
114-
115- public Builder threadName (String threadName ) {
116- this .threadName = threadName ;
117- return this ;
118- }
119-
120- public Builder category (String category ) {
121- this .category = category ;
122- return this ;
123- }
124-
125- public Builder lineNumber (String lineNumber ) {
126- this .lineNumber = lineNumber ;
127- return this ;
128- }
129-
130- public Builder message (String message ) {
131- this .message = message ;
132- return this ;
133- }
134-
135- public Builder throwableInformation (String throwableInformation ) {
136- this .throwableInformation = throwableInformation ;
137- return this ;
39+ public ServerLogItem (Map <String , Object > properties ) {
40+ if (properties != null ) {
41+ this .context = new HashMap <>(properties );
42+ } else {
43+ this .context = new HashMap <>();
13844 }
13945
140- public ServerLogItem build () {
141- return new ServerLogItem (this );
142- }
46+ this .serverId = (String ) context .getOrDefault ("serverId" , "" );
47+ this .id = (Long ) context .getOrDefault ("id" , "" );
48+ this .channelId = (String ) context .getOrDefault ("channelId" , "" );
49+ this .channelName = (String ) context .getOrDefault ("channelName" , "" );
50+ this .level = (String ) context .getOrDefault ("level" , "" );
51+ this .date = (Date ) context .getOrDefault ("date" , "" );
52+ this .threadName = (String ) context .getOrDefault ("threadName" , "" );
53+ this .category = (String ) context .getOrDefault ("category" , "" );
54+ this .lineNumber = (String ) context .getOrDefault ("lineNumber" , "" );
55+ this .message = (String ) context .getOrDefault ("message" , "" );
56+ this .throwableInformation = (String ) context .getOrDefault ("throwableInformation" , "" );
14357 }
14458
14559 public String getServerId () {
@@ -229,6 +143,14 @@ public String getChannelName() {
229143 public void setChannelName (String channelName ) {
230144 this .channelName = channelName ;
231145 }
146+
147+ public Map <String , Object > getContext () {
148+ return context ;
149+ }
150+
151+ public void setContext (Map <String , Object > context ) {
152+ this .context = new HashMap <>(context );
153+ }
232154
233155 @ Override
234156 public String toString () {
0 commit comments