From bab28f4b3da81da1bc6c0cb17d0fa8ae56c812a2 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 20 Sep 2018 12:29:27 -0400 Subject: [PATCH] Fix file log levels among other things --- README.md | 4 ++-- build/Dockerfile | 5 ++--- build/tgs.docker.sh | 1 - .../Configuration/GeneralConfiguration.cs | 5 +++++ src/Tgstation.Server.Host/Core/Application.cs | 9 ++++++++- .../appsettings.Docker.json | 19 ------------------- src/Tgstation.Server.Host/appsettings.json | 5 +---- 7 files changed, 18 insertions(+), 30 deletions(-) delete mode 100644 src/Tgstation.Server.Host/appsettings.Docker.json diff --git a/README.md b/README.md index 9d7ba1a5c8..cc56545b7d 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,9 @@ Create an `appsettings.Production.json` file next to `appsettings.json`. This wi - `General:GitHubAccessToken`: Specify a GitHub personal access token with no scopes here to highly mitigate the possiblity of 429 response codes from GitHub requests -- `Logging:LogLevel:Default`: Can be one of `Trace`, `Debug`, `Information`, `Warning`, `Error`, or `Critical`. Restricts what is put into the log files. Currently `Debug` is reccommended for help with error reporting. +- `General:LogFileLevel`: Can be one of `Trace`, `Debug`, `Information`, `Warning`, `Error`, or `Critical`. Restricts what is put into the log files. Currently `Debug` is reccommended for help with error reporting. -- `Kestrel:Endpoints:Http:Url`: The URL (i.e. interface and ports) your application should listen on. General use case should be `http://localhost:` for restricted local connections. See the Remote Access section for configuring public access to the World Wide Web. +- `Kestrel:Endpoints:Http:Url`: The URL (i.e. interface and ports) your application should listen on. General use case should be `http://localhost:` for restricted local connections. See the Remote Access section for configuring public access to the World Wide Web. This doesn't need to be changed using the docker setup and should be mapped with the `-p` option instead - `Database:DatabaseType`: Can be one of `SqlServer`, `MariaDB`, or `MySql` diff --git a/build/Dockerfile b/build/Dockerfile index 270755a249..240aeb77f9 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -20,7 +20,7 @@ WORKDIR /src/src/Tgstation.Server.Host RUN dotnet publish -c Release -o /app/lib/Default && mv /app/lib/Default/appsettings* /app FROM microsoft/dotnet:2.1-aspnetcore-runtime -EXPOSE 5000 +EXPOSE 80 #needed for byond RUN apt-get update \ @@ -32,9 +32,8 @@ WORKDIR /app COPY --from=build /app . COPY --from=build /src/build/tgs.docker.sh tgs.sh -COPY --from=build /src/src/Tgstation.Server.Host/appsettings.Docker.json . -RUN mkdir /config_data && mv appsettings.Docker.json /config_data/appsettings.Production.json +RUN mkdir /config_data VOLUME ["/config_data", "/tgs_logs", "/app/lib"] ENTRYPOINT ["./tgs.sh"] diff --git a/build/tgs.docker.sh b/build/tgs.docker.sh index f397e9b9b5..da2ae831f3 100755 --- a/build/tgs.docker.sh +++ b/build/tgs.docker.sh @@ -1,6 +1,5 @@ #!/bin/sh -mkdir /config_data cp -r /config_data/* ./ exec dotnet Tgstation.Server.Host.Console.dll "$@" diff --git a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs index 0451038e48..fc5cf03f09 100644 --- a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs @@ -15,6 +15,11 @@ /// public string LogFileDirectory { get; set; } + /// + /// The stringified for file logging + /// + public string LogFileLevel { get; set; } + /// /// If file logging is disabled /// diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 0abd7cadaf..9ee1c8eca9 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -54,6 +54,12 @@ namespace Tgstation.Server.Host.Core readonly Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment; readonly TaskCompletionSource startupTcs; + static LogLevel GetMinimumLogLevel(string stringLevel) + { + if (String.IsNullOrWhiteSpace(stringLevel) || !Enum.TryParse(stringLevel, out var minimumLevel)) + minimumLevel = LogLevel.Information; + return minimumLevel; + } /// /// Construct an @@ -94,7 +100,8 @@ namespace Tgstation.Server.Host.Core if (generalConfiguration?.DisableFileLogging != true) { var logPath = !String.IsNullOrEmpty(generalConfiguration?.LogFileDirectory) ? generalConfiguration.LogFileDirectory : ioManager.ConcatPath(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), VersionPrefix, "Logs"); - services.AddLogging(builder => builder.AddFile(ioManager.ConcatPath(logPath, "tgs-{Date}.log"))); + + services.AddLogging(builder => builder.AddFile(ioManager.ConcatPath(logPath, "tgs-{Date}.log"), GetMinimumLogLevel(generalConfiguration?.LogFileLevel))); } services.AddOptions(); diff --git a/src/Tgstation.Server.Host/appsettings.Docker.json b/src/Tgstation.Server.Host/appsettings.Docker.json deleted file mode 100644 index 142c7e376b..0000000000 --- a/src/Tgstation.Server.Host/appsettings.Docker.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "General": { - "LogFileDirectory": "/tgs_logs", - "MinimumPasswordLength": 15, - "GitHubAccessToken": null - }, - "Kestrel": { - "Endpoints": { - "Http": { - "Url": "http://localhost:5000" - } - } - }, - "Database": { - "DatabaseType": "SqlServer or MySQL or MariaDB", - "ConnectionString": "", - "MySqlServerVersion": "" - } -} diff --git a/src/Tgstation.Server.Host/appsettings.json b/src/Tgstation.Server.Host/appsettings.json index 79fa36f60b..0504931d30 100644 --- a/src/Tgstation.Server.Host/appsettings.json +++ b/src/Tgstation.Server.Host/appsettings.json @@ -2,6 +2,7 @@ "General": { "LogFileDirectory": null, //use the default path "DisableFileLogging": false, + "LogFileLevel": "Debug", "MinimumPasswordLength": 15, "GitHubAccessToken": null }, @@ -25,10 +26,6 @@ "Default": "Trace", "Microsoft": "Warning" } - }, - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning" } }, "Updates": {