Telemetry / logging work in progress

This commit is contained in:
Daniel Schick 2025-04-28 14:54:49 +02:00
parent d180dac600
commit 55254b20f7
8 changed files with 52 additions and 9 deletions

View File

@ -9,10 +9,11 @@
<section name="BreCalClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<log4net>
<log4net debug="true">
<root>
<level value="DEBUG"/>
<appender-ref ref="LogFileAppender"/>
<appender-ref ref="loki" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="log-BreCalClient.txt"/>
@ -25,6 +26,28 @@
<param name="ConversionPattern" value="%date [%thread] %-5level [%logger] - %message%newline"/>
</layout>
</appender>
<appender name="loki" type="Log4Net.Appender.Loki.LokiAppender, Log4Net.Appender.Grafana.Loki">
<Environment value="Development" />
<!-- Global label to be added to the log stream -->
<Application value="BreCal" />
<!-- Global label to be added to the log stream -->
<BufferSize value="512" />
<!-- To configure the buffer size, default: 512 -->
<ServiceUrl value="http://loki:3100" />
<!-- Loki URL -->
<!--BasicAuthUserName value="" /-->
<!-- To be added if basic authent enabled -->
<!--BasicAuthPassword value="" /-->
<!-- To be added if basic authent enabled -->
<GZipCompression value="true" />
<!-- To compress the post request using GZip compression -->
<TrustSelfSignedCerts value="false" />
<!-- To trust self signed certificates. Default: false -->
<Labels>
<Label name="host" value="%property{log4net:HostName}" />
<Label name="logger" value="%logger" />
</Labels>
</appender>
</log4net>
<applicationSettings>
<BreCalClient.Properties.Settings>

View File

@ -18,6 +18,9 @@ namespace BreCalClient
private void Application_Startup(object sender, StartupEventArgs e)
{
// Configure the logger
log4net.Config.XmlConfigurator.Configure();
// Window size sanity check
if (Settings.Default.Width == 0)
{

View File

@ -120,7 +120,7 @@ namespace BreCalClient
if (!_notificationsCollection.Where(x => x.Id == notification.Id).Any())
{
List<AppNotification> newList = new(_notificationsCollection);
List<AppNotification> newList = [.. _notificationsCollection];
AppNotification ap = new(notification.Id)
{

View File

@ -118,12 +118,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.6.1" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.7.25104.5739" />
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
<PackageReference Include="log4net" Version="3.0.3" />
<PackageReference Include="log4net" Version="3.0.4" />
<PackageReference Include="Log4Net.Appender.Grafana.Loki" Version="1.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly" Version="8.5.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="Polly" Version="8.5.2" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="ToastNotifications" Version="2.5.1" />
<PackageReference Include="ToastNotifications.Messages" Version="2.5.1" />
</ItemGroup>

View File

@ -141,6 +141,7 @@ namespace BreCalClient
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_log.Info("Client startup");
labelGeneralStatus.Text = $"Connection {ConnectionStatus.UNDEFINED}";
labelVersion.Text = "V. " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
if (!string.IsNullOrEmpty(Properties.Settings.Default.APP_TITLE))
@ -157,6 +158,7 @@ namespace BreCalClient
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
_log.Info("Client closing");
// serialize filter settings
Properties.Settings.Default.FilterCriteriaMap = SearchFilterModel.Serialize();
Properties.Settings.Default.Save();

View File

@ -292,6 +292,7 @@ namespace BreCalClient
if((this.ShipcallControlModel?.Shipcall?.Type == ShipcallType.Arrival) && (this.ShipcallControlModel?.Shipcall.TimeRefPoint != null))
{
int timeRefPointIndex = this.ShipcallControlModel?.Shipcall?.TimeRefPoint ?? 0;
if (timeRefPointIndex < 0) timeRefPointIndex = 0;
this.labelETAETDAgent.Content = BreCalLists.TimeRefs[timeRefPointIndex];
this.labelETAETDMooring.Content = BreCalLists.TimeRefs[timeRefPointIndex];

View File

@ -3,6 +3,9 @@ from flask import Flask
import os
import logging
from . import local_db
import logging_loki
import logging.handlers
from multiprocessing import Queue
from .api import shipcalls
from .api import participant
@ -70,6 +73,16 @@ def create_app(test_config=None, instance_path=None):
app.register_blueprint(ports.bp)
logging.basicConfig(filename='brecaltest.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s')
handler = logging_loki.LokiQueueHandler(
Queue(-1),
url="http://loki.fritz.box:3100/loki/api/v1/push",
tags={"application": "brecal"},
version="1",
)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(handler)
local_db.initPool(os.path.dirname(app.instance_path))
logging.info('App started')

View File

@ -13,7 +13,7 @@ def initPool(instancePath, connection_filename="connection_data_test.json"):
if(config_path == None):
config_path = os.path.join(instancePath,f'../../../secure/{connection_filename}') #connection_data_test.json');
# config_path = "E:/temp/connection_data.json"
config_path = "E:/temp/connection_data.json"
print (config_path)
if not os.path.exists(config_path):
@ -35,7 +35,7 @@ def initPool(instancePath, connection_filename="connection_data_test.json"):
credentials_file = "email_credentials_test.json"
credentials_path = os.path.join(instancePath,f'../../../secure/{credentials_file}')
# credentials_path = "E:/temp/email_credentials_devel.json"
credentials_path = "E:/temp/email_credentials_devel.json"
if not os.path.exists(credentials_path):
print ('cannot find ' + os.path.abspath(credentials_path))