Skip to content

Commit c9750dc

Browse files
committed
Improved Syslog parsing
1 parent 045aaba commit c9750dc

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/Couchcoding.Logbert.Gui/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.6.0.0")]
35-
[assembly: AssemblyFileVersion("1.6.0.0")]
34+
[assembly: AssemblyVersion("1.6.0.1")]
35+
[assembly: AssemblyFileVersion("1.6.0.1")]

src/Couchcoding.Logbert.Theme/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.6.0.0")]
35-
[assembly: AssemblyFileVersion("1.6.0.0")]
34+
[assembly: AssemblyVersion("1.6.0.1")]
35+
[assembly: AssemblyFileVersion("1.6.0.1")]

src/Logbert/Logging/LogMessageSyslog.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public sealed class LogMessageSyslog : LogMessage
7575
/// <summary>
7676
/// The <see cref="Regex"/> to parse a syslog <see cref="LogMessage"/>.
7777
/// </summary>
78-
private static readonly Regex mSyslogLineRegex = new Regex(@"<([0-9]{1,3})>", RegexOptions.IgnoreCase);
78+
private static readonly Regex mSyslogLineRegex = new Regex(@"<([0-9]{1,3})>([\s]?[\d]+\s)?(.*)", RegexOptions.IgnoreCase);
7979

8080
#endregion
8181

@@ -243,11 +243,11 @@ private bool ParseData(string data, string timestampFormat)
243243

244244
uint priMatrix = uint.Parse(msgMtc.Groups[1].Value);
245245

246-
mSeverity = (Severity)((int)priMatrix & 0x07);
247-
mFacility = (Facility)((int)priMatrix >> 3);
246+
mSeverity = (Severity)((int)priMatrix & 0x07);
247+
mFacility = (Facility)((int)priMatrix >> 3);
248248
mLocalTimestamp = DateTime.Now;
249249

250-
string syslogMessage = data.Substring(msgMtc.Groups[0].Length).TrimStart();
250+
string syslogMessage = msgMtc.Groups[3].Value.TrimStart();
251251
int hostIndex = 0;
252252
bool dtParseResult = false;
253253

@@ -277,14 +277,14 @@ private bool ParseData(string data, string timestampFormat)
277277
{
278278
mTimestamp = DateTime.Now;
279279
}
280-
280+
281281
syslogMessage = syslogMessage.Substring(hostIndex);
282-
mLogger = syslogMessage.Split(' ')[0];
283-
mMessage = syslogMessage.Substring(mLogger.Length + 1);
282+
mLogger = syslogMessage.TrimStart().Split(' ')[0];
283+
mMessage = syslogMessage.Substring(mLogger.Length + 1);
284284

285285
return true;
286286
}
287-
287+
288288
#endregion
289289

290290
#region Public Methods
@@ -360,17 +360,17 @@ public override Table ToLuaTable(Script owner)
360360
}
361361

362362
msgData["Facility"] = LogFacility.ToString();
363-
363+
364364
Table localTimeTable = new Table(owner);
365-
366-
localTimeTable["Day"] = Timestamp.Day;
367-
localTimeTable["Month"] = Timestamp.Month;
368-
localTimeTable["Year"] = Timestamp.Year;
369-
localTimeTable["Hour"] = Timestamp.Hour;
370-
localTimeTable["Minute"] = Timestamp.Minute;
371-
localTimeTable["Second"] = Timestamp.Second;
365+
366+
localTimeTable["Day"] = Timestamp.Day;
367+
localTimeTable["Month"] = Timestamp.Month;
368+
localTimeTable["Year"] = Timestamp.Year;
369+
localTimeTable["Hour"] = Timestamp.Hour;
370+
localTimeTable["Minute"] = Timestamp.Minute;
371+
localTimeTable["Second"] = Timestamp.Second;
372372
localTimeTable["Millisecond"] = Timestamp.Millisecond;
373-
localTimeTable["Timestamp"] = Timestamp.ToUnixTimestamp();
373+
localTimeTable["Timestamp"] = Timestamp.ToUnixTimestamp();
374374

375375
msgData["LocalTimestamp"] = localTimeTable;
376376

src/Logbert/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
// Build Number
3030
// Revision
3131
//
32-
[assembly: AssemblyVersion("1.6.0.0")]
33-
[assembly: AssemblyFileVersion("1.6.0.0")]
32+
[assembly: AssemblyVersion("1.6.0.1")]
33+
[assembly: AssemblyFileVersion("1.6.0.1")]
3434
[assembly: NeutralResourcesLanguageAttribute("")]

0 commit comments

Comments
 (0)