Skip to content

Commit dde8a91

Browse files
committed
new debug loggers
Create separate loggers for gathering data about yield returns and database contents. These logs will be in the same directory as the main "debug.log" file, but they will have the names: debugRootPrefTables debugYieldReturn debugMedia debugRoots They are created fresh each run (old file is deleted before logging starts).
1 parent 3365e23 commit dde8a91

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

src/Files.App/Utils/Cloud/Detector/GoogleDriveCloudDetector.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.Data.Sqlite;
5-
using System.IO;
6-
using Windows.Storage;
75
using Microsoft.Extensions.Logging;
86
using Microsoft.Win32;
7+
using System.IO;
8+
using Windows.Storage;
99

1010
namespace Files.App.Utils.Cloud
1111
{
@@ -26,6 +26,13 @@ public sealed class GoogleDriveCloudDetector : AbstractCloudDetector
2626

2727
protected override async IAsyncEnumerable<ICloudProvider> GetProviders()
2828
{
29+
30+
// TESTING
31+
var rootsLogger = GetAltLogger("debugRoots");
32+
var mediaLogger = GetAltLogger("debugMedia");
33+
var yieldReturnLogger = GetAltLogger("debugYieldReturn");
34+
var rootPrefTablesLogger = GetAltLogger("debugRootPrefTables");
35+
2936
// Google Drive's sync database can be in a couple different locations. Go find it.
3037
string appDataPath = UserDataPaths.GetDefault().LocalAppData;
3138

@@ -70,6 +77,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
7077

7178
App.AppModel.GoogleDrivePath = path;
7279

80+
// TESTING
81+
yieldReturnLogger.LogInformation("YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (roots): ");
82+
yieldReturnLogger.LogInformation("name=" + $"Google Drive ({title}); path=" + path);
83+
7384
yield return new CloudProvider(CloudProviders.GoogleDrive)
7485
{
7586
Name = $"Google Drive ({title})",
@@ -93,6 +104,10 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
93104

94105
StorageFile? iconFile = await GetGoogleDriveIconFileAsync();
95106

107+
// TESTING
108+
yieldReturnLogger.LogInformation("YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (media): ");
109+
yieldReturnLogger.LogInformation("name=" + title + "; path=" + path);
110+
96111
yield return new CloudProvider(CloudProviders.GoogleDrive)
97112
{
98113
Name = title,
@@ -101,12 +116,52 @@ await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(Path.Combine(a
101116
};
102117
}
103118

119+
// TESTING
120+
await Inspect(database, "SELECT * FROM roots", "root_preferences db, roots table", rootsLogger);
121+
await Inspect(database, "SELECT * FROM media", "root_preferences db, media table", mediaLogger);
122+
await Inspect(database, "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY 1",
123+
"root_preferences db, all tables", rootPrefTablesLogger);
124+
104125
await foreach (var provider in GetGoogleDriveProvidersFromRegistryAsync())
105126
{
127+
128+
// TESTING
129+
yieldReturnLogger.LogInformation("YIELD RETURNING from GoogleDriveCloudDetector#GetProviders (registry): ");
130+
yieldReturnLogger.LogInformation("name=" + provider.Name + "; path=" + provider.SyncFolder);
131+
106132
yield return provider;
107133
}
108134
}
109135

136+
// TESTING
137+
private async Task Inspect(SqliteConnection database, string sqlCommand, string contentsOf, ILogger logger)
138+
{
139+
await using var cmdTablesAll =
140+
new SqliteCommand(sqlCommand, database);
141+
var reader = await cmdTablesAll.ExecuteReaderAsync();
142+
var colNamesList = Enumerable.Range(0, reader.FieldCount).Select(j => reader.GetName(j)).ToList();
143+
var i = 0;
144+
logger.LogInformation("BEGIN LOGGING of " + contentsOf + " contents");
145+
while (reader.Read())
146+
{
147+
var colVals = new object[reader.FieldCount];
148+
reader.GetValues(colVals);
149+
colVals.Select((val, j) => $"row {i}: column {j}: {colNamesList[j]}: {val}").ToList()
150+
.ForEach(s => logger.LogInformation(s));
151+
i++;
152+
}
153+
logger.LogInformation("END LOGGING of " + contentsOf + " contents");
154+
155+
}
156+
157+
private ILogger GetAltLogger(string filename)
158+
{
159+
var altLogPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, filename);
160+
File.Delete(altLogPath);
161+
var factory = new LoggerFactory().AddFile(altLogPath);
162+
return factory.CreateLogger<App>();
163+
}
164+
110165
private JsonDocument? GetGoogleDriveRegValJson()
111166
{
112167
// This will be null if the key name is not found.

0 commit comments

Comments
 (0)