Add configuration setting for using local TZ
The default log timestamp is in UTC, this commit allows the user to convert the log timestamps to their own timezone. When approaching this problem I originally considered allowing the user to set any timezone offset of their choice. This would require some alignment between the device and client that was feeling cumbersome. In the end we decided to keep things relatively simple and just allow a simple toggle to convert log entries upon reading the logfile on the device. The default log timestamp emitted by the client remains UTC/Zulu Advances #2
This commit is contained in:
parent
2c2aa3d2b0
commit
affdc8a7bb
|
@ -142,6 +142,7 @@ class Site {
|
||||||
val cipher: String
|
val cipher: String
|
||||||
val sortKey: Int
|
val sortKey: Int
|
||||||
var logVerbosity: String
|
var logVerbosity: String
|
||||||
|
var logLocalTZ: Boolean?
|
||||||
var connected: Boolean?
|
var connected: Boolean?
|
||||||
var status: String?
|
var status: String?
|
||||||
val logFile: String?
|
val logFile: String?
|
||||||
|
@ -172,6 +173,7 @@ class Site {
|
||||||
sortKey = incomingSite.sortKey ?: 0
|
sortKey = incomingSite.sortKey ?: 0
|
||||||
logFile = siteDir.resolve("log").absolutePath
|
logFile = siteDir.resolve("log").absolutePath
|
||||||
logVerbosity = incomingSite.logVerbosity ?: "info"
|
logVerbosity = incomingSite.logVerbosity ?: "info"
|
||||||
|
logLocalTZ = incomingSite.logLocalTZ ?: false
|
||||||
|
|
||||||
connected = false
|
connected = false
|
||||||
status = "Disconnected"
|
status = "Disconnected"
|
||||||
|
@ -251,6 +253,7 @@ class IncomingSite(
|
||||||
val cipher: String,
|
val cipher: String,
|
||||||
val sortKey: Int?,
|
val sortKey: Int?,
|
||||||
var logVerbosity: String?,
|
var logVerbosity: String?,
|
||||||
|
val logLocalTZ: Boolean?,
|
||||||
@Expose(serialize = false)
|
@Expose(serialize = false)
|
||||||
var key: String?
|
var key: String?
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Site {
|
||||||
String status;
|
String status;
|
||||||
String logFile;
|
String logFile;
|
||||||
String logVerbosity;
|
String logVerbosity;
|
||||||
|
bool logLocalTZ;
|
||||||
|
|
||||||
// A list of errors encountered while loading the site
|
// A list of errors encountered while loading the site
|
||||||
List<String> errors;
|
List<String> errors;
|
||||||
|
@ -62,6 +63,7 @@ class Site {
|
||||||
this.status,
|
this.status,
|
||||||
this.logFile,
|
this.logFile,
|
||||||
this.logVerbosity = 'info',
|
this.logVerbosity = 'info',
|
||||||
|
this.logLocalTZ,
|
||||||
errors,
|
errors,
|
||||||
unsafeRoutes})
|
unsafeRoutes})
|
||||||
: staticHostmap = staticHostmap ?? {},
|
: staticHostmap = staticHostmap ?? {},
|
||||||
|
@ -105,6 +107,7 @@ class Site {
|
||||||
sortKey = json['sortKey'];
|
sortKey = json['sortKey'];
|
||||||
logFile = json['logFile'];
|
logFile = json['logFile'];
|
||||||
logVerbosity = json['logVerbosity'];
|
logVerbosity = json['logVerbosity'];
|
||||||
|
logLocalTZ = json['logLocalTZ'];
|
||||||
connected = json['connected'] ?? false;
|
connected = json['connected'] ?? false;
|
||||||
status = json['status'] ?? "";
|
status = json['status'] ?? "";
|
||||||
|
|
||||||
|
@ -154,6 +157,7 @@ class Site {
|
||||||
'cipher': cipher,
|
'cipher': cipher,
|
||||||
'sortKey': sortKey,
|
'sortKey': sortKey,
|
||||||
'logVerbosity': logVerbosity,
|
'logVerbosity': logVerbosity,
|
||||||
|
'logLocalTZ': logLocalTZ,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,10 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
|
||||||
loadLogs() async {
|
loadLogs() async {
|
||||||
var file = File(widget.site.logFile);
|
var file = File(widget.site.logFile);
|
||||||
try {
|
try {
|
||||||
final v = await file.readAsString();
|
String v = await file.readAsString();
|
||||||
|
if(widget.site.logLocalTZ) {
|
||||||
|
v = convertToLocalTZ(v);
|
||||||
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
logs = v;
|
logs = v;
|
||||||
});
|
});
|
||||||
|
@ -115,6 +117,17 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertToLocalTZ(String rawLog) {
|
||||||
|
// Regex to extract time value
|
||||||
|
rawLog = rawLog.replaceAllMapped(RegExp('time="(.*?)"'), (match){
|
||||||
|
// Convert to DateTime with the inner match from above
|
||||||
|
DateTime userDate = DateTime.parse(match.group(1));
|
||||||
|
// Return timestamp in format that matches default
|
||||||
|
return 'time="${userDate.toLocal().toIso8601String()}"';
|
||||||
|
});
|
||||||
|
return rawLog;
|
||||||
|
}
|
||||||
|
|
||||||
deleteLogs() async {
|
deleteLogs() async {
|
||||||
var file = File(widget.site.logFile);
|
var file = File(widget.site.logFile);
|
||||||
await file.writeAsBytes([]);
|
await file.writeAsBytes([]);
|
||||||
|
|
|
@ -28,6 +28,7 @@ class Advanced {
|
||||||
String verbosity;
|
String verbosity;
|
||||||
List<UnsafeRoute> unsafeRoutes;
|
List<UnsafeRoute> unsafeRoutes;
|
||||||
int mtu;
|
int mtu;
|
||||||
|
bool logLocalTZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AdvancedScreen extends StatefulWidget {
|
class AdvancedScreen extends StatefulWidget {
|
||||||
|
@ -52,6 +53,7 @@ class _AdvancedScreenState extends State<AdvancedScreen> {
|
||||||
settings.verbosity = widget.site.logVerbosity;
|
settings.verbosity = widget.site.logVerbosity;
|
||||||
settings.unsafeRoutes = widget.site.unsafeRoutes;
|
settings.unsafeRoutes = widget.site.unsafeRoutes;
|
||||||
settings.mtu = widget.site.mtu;
|
settings.mtu = widget.site.mtu;
|
||||||
|
settings.logLocalTZ = widget.site.logLocalTZ;
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +133,22 @@ class _AdvancedScreenState extends State<AdvancedScreen> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
ConfigItem(
|
||||||
|
label: Text('Use Local Time Zone'),
|
||||||
|
labelWidth: 200,
|
||||||
|
content: Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Switch.adaptive(
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
value: settings.logLocalTZ,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
settings.logLocalTZ = value;
|
||||||
|
changed = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
),
|
||||||
ConfigPageItem(
|
ConfigPageItem(
|
||||||
label: Text('Log verbosity'),
|
label: Text('Log verbosity'),
|
||||||
labelWidth: 150,
|
labelWidth: 150,
|
||||||
|
|
|
@ -218,6 +218,7 @@ class _SiteConfigScreenState extends State<SiteConfigScreen> {
|
||||||
site.lhDuration = settings.lhDuration;
|
site.lhDuration = settings.lhDuration;
|
||||||
site.port = settings.port;
|
site.port = settings.port;
|
||||||
site.logVerbosity = settings.verbosity;
|
site.logVerbosity = settings.verbosity;
|
||||||
|
site.logLocalTZ = settings.logLocalTZ;
|
||||||
site.unsafeRoutes = settings.unsafeRoutes;
|
site.unsafeRoutes = settings.unsafeRoutes;
|
||||||
site.mtu = settings.mtu;
|
site.mtu = settings.mtu;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue