From 4c8a57eb1ded0c28c4f7e91bf9685780640871f9 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 28 Feb 2023 08:21:33 +0200 Subject: [PATCH] Logging - Placed most of logging setup into a mixin template called `LoggerSetup` App - Use the new `LoggerSetup` mixin Server - Use the new `LoggerSetup` mixin --- source/nostril/app.d | 16 ++-------------- source/nostril/logging.d | 18 ++++++++++++++++++ source/nostril/server.d | 17 +++++++++++------ 3 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 source/nostril/logging.d diff --git a/source/nostril/app.d b/source/nostril/app.d index ca96121..7cd372e 100644 --- a/source/nostril/app.d +++ b/source/nostril/app.d @@ -1,20 +1,8 @@ module nostril.app; -import std.stdio; - -import vibe.vibe; -import vibe.http.dist; -import std.json; - -import gogga; - -// TODO: Investigate if we need the belowe (I copied it from Birchwood) -__gshared GoggaLogger logger; -__gshared static this() -{ - logger = new GoggaLogger(); -} +import nostril.logging : LoggerSetup; +mixin LoggerSetup!(); import nostril.server; void main() diff --git a/source/nostril/logging.d b/source/nostril/logging.d new file mode 100644 index 0000000..dc8d824 --- /dev/null +++ b/source/nostril/logging.d @@ -0,0 +1,18 @@ +module nostril.logging; + +mixin template LoggerSetup() +{ + import gogga; + + // TODO: Investigate if we need the belowe (I copied it from Birchwood) + __gshared GoggaLogger logger; + __gshared static this() + { + logger = new GoggaLogger(); + + version(dbg) + { + logger.enableDebug(); + } + } +} \ No newline at end of file diff --git a/source/nostril/server.d b/source/nostril/server.d index a0ce188..7456a2c 100644 --- a/source/nostril/server.d +++ b/source/nostril/server.d @@ -1,13 +1,14 @@ module nostril.server; +import nostril.logging; + + +/** + * FIXME: Fix the below so I need not import gogga too + */ +mixin LoggerSetup!(); import gogga; -// TODO: Investigate if we need the belowe (I copied it from Birchwood) -__gshared GoggaLogger logger; -__gshared static this() -{ - logger = new GoggaLogger(); -} import core.thread : Thread; @@ -102,7 +103,9 @@ public class Server */ public final void addConnection(Connection newConnection) { + logger.dbg("Adding connection '"~newConnection.toString()~"'...\n", DebugType.WARNING); connections[newConnection] = newConnection; + logger.dbg("Adding connection '"~newConnection.toString()~"'... [done]\n", DebugType.WARNING); } /** @@ -113,7 +116,9 @@ public class Server */ public final void delConnection(Connection existingConnection) { + logger.dbg("Removing connection '"~existingConnection.toString()~"'...\n", DebugType.WARNING); connections.remove(existingConnection); + logger.dbg("Removing connection '"~existingConnection.toString()~"'... [done]\n", DebugType.WARNING); } }