1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 14:23:38 +02:00
- Use new logging facility
This commit is contained in:
Tristan B. Velloza Kildaire 2024-05-12 17:58:17 +02:00
parent be8ccbee2b
commit f70d063591

View File

@ -19,14 +19,7 @@ import birchwood.protocol.constants : ReplyType;
import birchwood.client.receiver : ReceiverThread; import birchwood.client.receiver : ReceiverThread;
import birchwood.client.sender : SenderThread; import birchwood.client.sender : SenderThread;
import birchwood.client.events; import birchwood.client.events;
import birchwood.logging;
import dlog;
package __gshared Logger logger;
__gshared static this()
{
logger = new DefaultLogger();
}
// TODO: Make abstract and for unit tests make a `DefaultClient` // TODO: Make abstract and for unit tests make a `DefaultClient`
// ... which logs outputs for the `onX()` handler functions // ... which logs outputs for the `onX()` handler functions
@ -136,7 +129,7 @@ public class Client : Thread
public void onChannelMessage(Message fullMessage, string channel, string msgBody) public void onChannelMessage(Message fullMessage, string channel, string msgBody)
{ {
/* Default implementation */ /* Default implementation */
logger.log("Channel("~channel~"): "~msgBody); DEBUG("Channel("~channel~"): "~msgBody);
} }
/** /**
@ -150,7 +143,7 @@ public class Client : Thread
public void onDirectMessage(Message fullMessage, string nickname, string msgBody) public void onDirectMessage(Message fullMessage, string nickname, string msgBody)
{ {
/* Default implementation */ /* Default implementation */
logger.log("DirectMessage("~nickname~"): "~msgBody); DEBUG("DirectMessage("~nickname~"): "~msgBody);
} }
/** /**
@ -162,7 +155,7 @@ public class Client : Thread
public void onGenericCommand(Message message) public void onGenericCommand(Message message)
{ {
/* Default implementation */ /* Default implementation */
logger.log("Generic("~message.getCommand()~", "~message.getFrom()~"): "~message.getParams()); DEBUG("Generic("~message.getCommand()~", "~message.getFrom()~"): "~message.getParams());
} }
// TODO: Hook certain ones default style with an implemenation // TODO: Hook certain ones default style with an implemenation
@ -179,29 +172,29 @@ public class Client : Thread
// ... state // ... state
/* Default implementation */ /* Default implementation */
logger.log("Response("~to!(string)(commandReply.getReplyType())~", "~commandReply.getFrom()~"): "~commandReply.toString()); DEBUG("Response("~to!(string)(commandReply.getReplyType())~", "~commandReply.getFrom()~"): "~commandReply.toString());
if(commandReply.getReplyType() == ReplyType.RPL_ISUPPORT) if(commandReply.getReplyType() == ReplyType.RPL_ISUPPORT)
{ {
// TODO: Testing code was here // TODO: Testing code was here
// logger.log(); // DEBUG();
// logger.log("<<<>>>"); // DEBUG("<<<>>>");
// logger.log("Take a look:\n\n"~commandReply.getParams()); // DEBUG("Take a look:\n\n"~commandReply.getParams());
// logger.log("And here is key-value pairs: ", commandReply.getKVPairs()); // DEBUG("And here is key-value pairs: ", commandReply.getKVPairs());
// logger.log("And here is array: ", commandReply.getPairs()); // DEBUG("And here is array: ", commandReply.getPairs());
// // TODO: DLog bug, this prints nothing // // TODO: DLog bug, this prints nothing
// logger.log("And here is trailing: ", commandReply.getTrailing()); // DEBUG("And here is trailing: ", commandReply.getTrailing());
// import std.stdio; // import std.stdio;
// writeln("Trailer: "~commandReply.getTrailing()); // writeln("Trailer: "~commandReply.getTrailing());
// writeln(cast(ubyte[])commandReply.getTrailing()); // writeln(cast(ubyte[])commandReply.getTrailing());
// logger.log("<<<>>>"); // DEBUG("<<<>>>");
// logger.log(); // DEBUG();
import std.stdio; import std.stdio;
writeln("Support stuff: ", commandReply.getKVPairs()); writeln("Support stuff: ", commandReply.getKVPairs());
@ -213,7 +206,7 @@ public class Client : Thread
/* Update the db */ /* Update the db */
string value = receivedKV[key]; string value = receivedKV[key];
connInfo.updateDB(key, value); connInfo.updateDB(key, value);
logger.log("Updated key in db '"~key~"' with value '"~value~"'"); DEBUG("Updated key in db '"~key~"' with value '"~value~"'");
} }
} }
@ -225,7 +218,7 @@ public class Client : Thread
public void onConnectionClosed() public void onConnectionClosed()
{ {
// TODO: Add log as default behaviour? // TODO: Add log as default behaviour?
logger.log("Connection was closed, not doing anything"); DEBUG("Connection was closed, not doing anything");
} }
/** /**
@ -773,7 +766,7 @@ public class Client : Thread
assert(ircEvent); //Should never fail, unless some BOZO regged multiple handles for 1 - wait idk does eventy do that even mmm assert(ircEvent); //Should never fail, unless some BOZO regged multiple handles for 1 - wait idk does eventy do that even mmm
// NOTE: Enable this when debugging // NOTE: Enable this when debugging
// logger.log("IRCEvent(message): "~ircEvent.getMessage().toString()); // DEBUG("IRCEvent(message): "~ircEvent.getMessage().toString());
/* TODO: We should use a switch statement, imagine how nice */ /* TODO: We should use a switch statement, imagine how nice */
Message ircMessage = ircEvent.getMessage(); Message ircMessage = ircEvent.getMessage();
@ -849,7 +842,7 @@ public class Client : Thread
// string messageToSend = "PONG "~pongEvent.getID(); // string messageToSend = "PONG "~pongEvent.getID();
Message pongMessage = new Message("", "PONG", pongEvent.getID()); Message pongMessage = new Message("", "PONG", pongEvent.getID());
client.sendMessage(pongMessage); client.sendMessage(pongMessage);
logger.log("Ponged back with "~pongEvent.getID()); DEBUG("Ponged back with "~pongEvent.getID());
} }
} }
engine.addSignalHandler(new PongSignal(this)); engine.addSignalHandler(new PongSignal(this));
@ -1034,7 +1027,7 @@ public class Client : Thread
{ {
/* Set the state of running to false */ /* Set the state of running to false */
running = false; running = false;
logger.log("disconnect() begin"); DEBUG("disconnect() begin");
/* Shutdown the socket */ /* Shutdown the socket */
@ -1048,7 +1041,7 @@ public class Client : Thread
*/ */
import std.socket : SocketShutdown; import std.socket : SocketShutdown;
socket.shutdown(SocketShutdown.BOTH); socket.shutdown(SocketShutdown.BOTH);
logger.log("disconnect() socket shutdown"); DEBUG("disconnect() socket shutdown");
} }
@ -1062,20 +1055,20 @@ public class Client : Thread
{ {
/* Stop the receive queue manager and wait for it to stop */ /* Stop the receive queue manager and wait for it to stop */
receiver.end(); receiver.end();
logger.log("doThreadCleanup() recvQueue manager stopped"); DEBUG("doThreadCleanup() recvQueue manager stopped");
receiver = null; receiver = null;
/* Stop the send queue manager and wait for it to stop */ /* Stop the send queue manager and wait for it to stop */
sender.end(); sender.end();
logger.log("doThreadCleanup() sendQueue manager stopped"); DEBUG("doThreadCleanup() sendQueue manager stopped");
sender = null; sender = null;
/* TODO: Stop eventy (FIXME: I don't know if this is implemented in Eventy yet, do this!) */ /* TODO: Stop eventy (FIXME: I don't know if this is implemented in Eventy yet, do this!) */
engine.shutdown(); engine.shutdown();
logger.log("doThreadCleanup() eventy stopped"); DEBUG("doThreadCleanup() eventy stopped");
engine = null; engine = null;
logger.log("doThreadCleanup() end"); DEBUG("doThreadCleanup() end");
} }
/** /**
@ -1088,8 +1081,8 @@ public class Client : Thread
private void processMessage(ubyte[] message) private void processMessage(ubyte[] message)
{ {
// import std.stdio; // import std.stdio;
// logger.log("Message length: "~to!(string)(message.length)); // DEBUG("Message length: "~to!(string)(message.length));
// logger.log("InterpAsString: "~cast(string)message); // DEBUG("InterpAsString: "~cast(string)message);
receiveQ(message); receiveQ(message);
} }