Browse Source

Diagnostic logging is now controlled from settings.

Neal Wilson 10 years ago
parent
commit
f09b689715
3 changed files with 76 additions and 11 deletions
  1. 61
    0
      src/advancedsettings.w
  2. 5
    1
      src/settings.w
  3. 10
    10
      src/typica.w

+ 61
- 0
src/advancedsettings.w View File

@@ -0,0 +1,61 @@
1
+@* Advanced settings configuration.
2
+
3
+\noindent Sometimes a feature has a sensible default that should be used the
4
+vast majority of the time but sometimes requires some other setting to be
5
+available in a reasonably accessible way.
6
+
7
+@<Class declarations@>=
8
+class AdvancedSettingsWidget : public QWidget@/
9
+{@/
10
+	@[Q_OBJECT@]@;
11
+	public:@/
12
+		AdvancedSettingsWidget();
13
+	@[public slots:@]@/
14
+		void enableDiagnosticLogging(bool enabled);
15
+};
16
+
17
+@ At present the advanced settings consist only of an option to redirect
18
+diagnostic output to a file. This should normally be disabled as it supresses
19
+console output and there is no mechanism within \pn{} for periodically removing
20
+the files generated. It is, however, useful for producing a diagnostic file
21
+that can be attached to an email if someone is encountering an issue that they
22
+are not able to resolve on their own. It is especially useful on Microsoft
23
+Windows where this output is not otherwise available unless Typica is run from
24
+software development tools most people do not have installed.
25
+
26
+@<AdvancedSettingsWidget implementation@>=
27
+AdvancedSettingsWidget::AdvancedSettingsWidget() : QWidget(NULL)
28
+{
29
+	QSettings settings;
30
+	QFormLayout *layout = new QFormLayout;
31
+	QCheckBox *logDiagnostics = new QCheckBox;
32
+	logDiagnostics->setCheckState(
33
+		settings.value("settings/advanced/logging", false).toBool() ?
34
+		Qt::Checked : Qt::Unchecked);
35
+	connect(logDiagnostics, SIGNAL(toggled(bool)), this, SLOT(enableDiagnosticLogging(bool)));
36
+	layout->addRow(tr("Enable diagnostic logging"), logDiagnostics);
37
+	setLayout(layout);
38
+}
39
+
40
+@ Changes to this setting should take effect immediately. It should also be
41
+written to |QSettings| so the feature can be correctly enabled or not. 
42
+
43
+@<AdvancedSettingsWidget implementation@>=
44
+void AdvancedSettingsWidget::enableDiagnosticLogging(bool enabled)
45
+{
46
+	QSettings settings;
47
+	settings.setValue("settings/advanced/logging", enabled);
48
+	if(enabled)
49
+	{
50
+		qInstallMsgHandler(messageFileOutput);
51
+	}
52
+	else
53
+	{
54
+		qInstallMsgHandler(0);
55
+	}
56
+}
57
+
58
+@ Currently the implementation is brought into typica.cpp.
59
+
60
+@<Class implementations@>=
61
+@<AdvancedSettingsWidget implementation@>

+ 5
- 1
src/settings.w View File

@@ -31,6 +31,8 @@ SettingsWindow::SettingsWindow() : QMainWindow(NULL)
31 31
 	settingsTab->addTab(deviceSettings, tr("Roasters"));
32 32
 	GraphSettingsWidget *graphSettings = new GraphSettingsWidget;
33 33
 	settingsTab->addTab(graphSettings, tr("Graph"));
34
+	AdvancedSettingsWidget *advancedSettings = new AdvancedSettingsWidget;
35
+	settingsTab->addTab(advancedSettings, tr("Advanced"));
34 36
 	setCentralWidget(settingsTab);
35 37
 }
36 38
 
@@ -56,4 +58,6 @@ constructor = engine->newFunction(constructSettingsWindow);
56 58
 value = engine->newQMetaObject(&DeviceConfigurationWindow::staticMetaObject, constructor);
57 59
 engine->globalObject().setProperty("SettingsWindow", value);
58 60
 
59
-@i graphsettings.w
61
+@i graphsettings.w
62
+
63
+@i advancedsettings.w

+ 10
- 10
src/typica.w View File

@@ -12719,14 +12719,13 @@ build.
12719 12719
 @<The main program@>=
12720 12720
 int main(int argc, char **argv)@/
12721 12721
 {@/
12722
-	@<Set up logging@>@;
12723 12722
 	int *c = &argc;
12724 12723
 	Application app(*c, argv);
12724
+	QSettings settings;
12725
+	@<Set up logging@>@;
12725 12726
 	@<Set up icons@>@;
12726 12727
 	@<Set up fonts@>@;
12727 12728
 
12728
-	QSettings settings;
12729
-
12730 12729
 	@<Register device configuration widgets@>@;
12731 12730
 	@<Prepare the database connection@>@;
12732 12731
 	@<Load the application configuration@>@;
@@ -12739,14 +12738,15 @@ int main(int argc, char **argv)@/
12739 12738
 	return retval;@/
12740 12739
 }
12741 12740
 
12742
-@ Proof of concept for the introduction of logging warnings to a file. This is
12743
-primarily for the benefit of people using Windows without an attached debugger.
12744
-Before this is merged to development it should allow the person using Typica
12745
-more control over if this should be enabled (by default it should not) and
12746
-where the output is sent.
12741
+@ \pn{} 1.6.3 introduces optional logging of diagnostic messages to a file. By
12742
+default this feature is not enabled. A sensible future refinement to this would
12743
+allow specification of where this file should be created.
12747 12744
 
12748 12745
 @<Set up logging@>=
12749
-qInstallMsgHandler(messageFileOutput);
12746
+if(settings.value("settings/advanced/logging", false).toBool())
12747
+{
12748
+	qInstallMsgHandler(messageFileOutput);
12749
+}
12750 12750
 
12751 12751
 @ This requires that we have our messageFileOutput function.
12752 12752
 
@@ -12761,7 +12761,7 @@ void messageFileOutput(QtMsgType type, const char *msg)
12761 12761
 	QFile output("Typica-"+QDate::currentDate().toString("yyyy-MM-dd")+".log");
12762 12762
 	output.open(QIODevice::WriteOnly | QIODevice::Append);
12763 12763
 	QTextStream outstream(&output);
12764
-	outstream << msg << "\n";
12764
+	outstream << msg << "\r\n";
12765 12765
 }
12766 12766
 
12767 12767
 @ \pn{} 1.4 introduces the ability to use icons in certain interface elements.

Loading…
Cancel
Save