Skip to content

Commit 0b25e39

Browse files
committed
Extend QueryLog
Added - Duration - Cached - Server
1 parent 9e60cfa commit 0b25e39

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

SimpleDnsCrypt/Models/QueryLogLine.cs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
using Caliburn.Micro;
2+
using SimpleDnsCrypt.Helper;
3+
using System;
24

35
namespace SimpleDnsCrypt.Models
46
{
@@ -23,26 +25,51 @@ public enum QueryLogReturnCode
2325
PARSE_ERROR,
2426
NXDOMAIN,
2527
RESPONSE_ERROR,
26-
SERVER_ERROR
28+
SERVER_ERROR,
29+
CLOAK
2730
}
2831

2932
public class QueryLogLine : LogLine
3033
{
34+
private static readonly ILog Log = LogManagerHelper.Factory();
3135
public DateTime Date { get; set; }
3236
public string Address { get; set; }
3337
public string Remote { get; set; }
3438
public QueryLogLineType Type { get; set; }
3539
public QueryLogReturnCode ReturnCode { get; set; }
40+
public bool Cached { get; set; }
41+
public string CachedText {
42+
get
43+
{
44+
if (Cached)
45+
{
46+
return "cached";
47+
}
48+
else
49+
{
50+
return "live";
51+
}
52+
}
53+
}
54+
public long Duration { get; set; }
55+
public string DurationText
56+
{
57+
get
58+
{
59+
return $"{Duration}ms";
60+
}
61+
}
62+
public string Server { get; set; }
3663

3764
public QueryLogLine(string line)
3865
{
3966
try
4067
{
4168
//this only works with the ltsv log format:
42-
//time:1516734518 host:::1 message:stackoverflow.com type:A
69+
//time:1559589175 host:::1 message:www.test.de type:AAAA return:SYNTH cached:0 duration:0 server:freetsa.org
4370
var stringSeparators = new[] { "\t" };
4471
var parts = line.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
45-
if (parts.Length != 5) return;
72+
if (parts.Length != 8) return;
4673
if (parts[0].StartsWith("time:"))
4774
{
4875
Date = UnixTimeStampToDateTime(Convert.ToDouble(parts[0].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1]));
@@ -75,9 +102,22 @@ public QueryLogLine(string line)
75102
{
76103
Type = QueryLogLineType.Unknown;
77104
}
105+
if (parts[5].StartsWith("cached:"))
106+
{
107+
Cached = Convert.ToBoolean(Convert.ToInt16(parts[5].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim()));
108+
}
109+
if (parts[6].StartsWith("duration:"))
110+
{
111+
Duration = Convert.ToInt64(parts[6].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim());
112+
}
113+
if (parts[7].StartsWith("server:"))
114+
{
115+
Server = parts[7].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
116+
}
78117
}
79-
catch (Exception)
118+
catch (Exception exception)
80119
{
120+
Log.Error(exception);
81121
}
82122
}
83123
}

SimpleDnsCrypt/Views/MainView.xaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,11 @@
959959
<Grid.ColumnDefinitions>
960960
<ColumnDefinition Width="130" />
961961
<ColumnDefinition Width="40" />
962-
<ColumnDefinition Width="70" />
962+
<ColumnDefinition Width="90" />
963963
<ColumnDefinition Width="80" />
964+
<ColumnDefinition Width="160" />
965+
<ColumnDefinition Width="40" />
966+
<ColumnDefinition Width="50" />
964967
<ColumnDefinition Width="*" />
965968
</Grid.ColumnDefinitions>
966969
<TextBlock Grid.Column="0"
@@ -974,6 +977,12 @@
974977
Foreground="#FF575757" />
975978
<TextBlock Grid.Column="4" Text="{Binding Remote}"
976979
Foreground="#FF575757" />
980+
<TextBlock Grid.Column="5" Text="{Binding CachedText}"
981+
Foreground="#FF575757" />
982+
<TextBlock Grid.Column="6" Text="{Binding DurationText}"
983+
Foreground="#FF575757" />
984+
<TextBlock Grid.Column="7" Text="{Binding Server}"
985+
Foreground="#FF575757" />
977986
</Grid>
978987
</DataTemplate>
979988
</customControls:LoggingListView.ItemTemplate>

0 commit comments

Comments
 (0)