Add logLevel to app config.
Build and Deploy API / build-and-deploy (push) Successful in 1m15s Details

This commit is contained in:
Andrew Lalis 2025-08-09 11:29:20 -04:00
parent 2b5a18cf91
commit e0b998156d
1 changed files with 29 additions and 3 deletions

View File

@ -7,11 +7,22 @@ import api_mapping;
struct AppConfig {
ushort port;
string webOrigin;
string logLevel;
}
void main() {
const AppConfig config = readConfig();
auto provider = new DefaultProvider(Levels.TRACE);
Level logLevel = Levels.INFO;
if (config.logLevel == "TRACE") {
logLevel = Levels.TRACE;
} else if (config.logLevel == "DEBUG") {
logLevel = Levels.DEBUG;
} else if (config.logLevel == "WARN") {
logLevel = Levels.WARN;
} else if (config.logLevel == "ERROR") {
logLevel = Levels.ERROR;
}
auto provider = new DefaultProvider(logLevel);
configureLoggingProvider(provider);
infoF!"Loaded app config: port = %d, webOrigin = %s"(config.port, config.webOrigin);
@ -23,10 +34,25 @@ AppConfig readConfig() {
import std.file : exists, readText;
import std.json;
import std.conv : to;
AppConfig defaultConfig = AppConfig(
8080,
"http://localhost:5173",
"INFO"
);
// Local dev environment if no config is given.
if (!exists("finnow-api-config.json")) {
return AppConfig(8080, "http://localhost:5173");
return defaultConfig;
}
JSONValue obj = parseJSON(readText("finnow-api-config.json"));
return AppConfig(obj.object["port"].integer.to!ushort, obj.object["webOrigin"].str);
if ("port" in obj.object) {
defaultConfig.port = obj.object["port"].integer.to!ushort;
}
if ("webOrigin" in obj.object) {
defaultConfig.webOrigin = obj.object["webOrigin"].str;
}
if ("logLevel" in obj.object) {
defaultConfig.logLevel = obj.object["logLevel"].str;
}
return defaultConfig;
}