diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-08-11 21:40:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-11 21:40:31 -0500 |
| commit | e3b89745f0d1d18608d7183cb2af9e45c54d139e (patch) | |
| tree | 0b138988e5ac0b8dad2ea6bd225649020e19302f | |
| parent | e617b9bdf8d18633ec1e627b988793df161fa820 (diff) | |
| parent | 61ed248f48e76cf9bb4d32e18f9c08420a0218ce (diff) | |
| download | slskd-e3b89745f0d1d18608d7183cb2af9e45c54d139e.tar.gz | |
Merge pull request #582 from slskd/log-sql
Add an option to enable Entity Framework query logging
| -rw-r--r-- | config/slskd.example.yml | 1 | ||||
| -rw-r--r-- | docs/config.md | 2 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 9 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 5 |
4 files changed, 14 insertions, 3 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 893b2da8..d29a4eb9 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -7,6 +7,7 @@ # no_connect: false # no_share_scan: false # no_version_check: false +# log_sql: false # directories: # incomplete: ~ # downloads: ~ diff --git a/docs/config.md b/docs/config.md index 971e8288..bc975b4b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -698,6 +698,7 @@ A number of additional feature flags are provided to change the runtime behavior | `--no-connect` | `NO_CONNECT` | Start the application, but don't connect to the server | | `--no-share-scan` | `NO_SHARE_SCAN` | Don't perform a scan of shared directories on startup | | `--no-version-check` | `NO_VERSION_CHECK` | Don't perform a version check on startup | +| `--log-sql` | `LOG_SQL` | Log SQL queries generated by Entity Framework | #### **YAML** ```yaml @@ -708,6 +709,7 @@ flags: no_connect: false no_share_scan: false no_version_check: false + log_sql: false ``` # Commands diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index f2e89aeb..a1db929a 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -294,6 +294,15 @@ namespace slskd [Description("do not check for newer version at startup")] [RequiresRestart] public bool NoVersionCheck { get; init; } = false; + + /// <summary> + /// Gets a value indicating whether Entity Framework queries should be logged. + /// </summary> + [Argument(default, "log-sql")] + [EnvironmentVariable("LOG_SQL")] + [Description("log SQL queries generated by Entity Framework")] + [RequiresRestart] + public bool LogSQL { get; init; } = false; } /// <summary> diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index e733c086..702cf467 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -800,10 +800,9 @@ namespace slskd { options.UseSqlite($"Data Source={Path.Combine(AppDirectory, "data", filename)}"); - // tweak this to enable Entity Framework SQL logging - if (OptionsAtStartup.Debug && false) + if (OptionsAtStartup.Debug && OptionsAtStartup.Flags.LogSQL) { - options.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole())); + options.LogTo(Log.Debug, LogLevel.Information); } }); |
