- Placed most of logging setup into a mixin template called `LoggerSetup`

App

- Use the new `LoggerSetup` mixin

Server

- Use the new `LoggerSetup` mixin
This commit is contained in:
Tristan B. Velloza Kildaire 2023-02-28 08:21:33 +02:00
parent d453c16ad5
commit 4c8a57eb1d
3 changed files with 31 additions and 20 deletions

View File

@ -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()

18
source/nostril/logging.d Normal file
View File

@ -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();
}
}
}

View File

@ -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);
}
}