Added Logger

This commit is contained in:
dawidg81 2026-03-04 08:18:57 +01:00
commit c5a92b337e
3 changed files with 46 additions and 12 deletions

16
src/Core/Logger.cpp Normal file
View file

@ -0,0 +1,16 @@
#include "Logger.hpp"
void Logger::raw(std::string msg)
{
std::cout << msg << '\n';
}
void Logger::info(std::string msg)
{
std::cout << "[INFO] " << msg << '\n';
}
void Logger::err(std::string msg)
{
std::cerr << "[ERROR] " << msg << '\n';
}

11
src/Core/Logger.hpp Normal file
View file

@ -0,0 +1,11 @@
#pragma once
#include <iostream>
#include <string>
class Logger
{
public:
void raw(std::string msg);
void info(std::string msg);
void err(std::string msg);
};

View file

@ -1,4 +1,5 @@
#include <iostream>
#include "Core/Logger.hpp"
#include <winsock.h>
#define NET_SOCK_ADDR "0.0.0.0"
@ -6,25 +7,31 @@
using namespace std;
class Network {
Logger log;
class Network
{
public:
class Socket {
class Socket
{
public:
int winInit() {
int winInit()
{
WSADATA wsaData;
int result = WSAStartup( MAKEWORD(2, 2), & wsaData );
if (result != 0) cout << "Network.Socket.winInit: Error: Initialization error\n";
if (result != 0) log.err("Network.Socket.winInit: Initialization error");
cout << "Network.Socket.winInit: Socket initialized\n";
log.info("Network.Socket.winInit: Socket initialized");
SOCKET mainSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if (mainSocket == INVALID_SOCKET) {
cout << "Network.Socket.winInit: Fatal error: Error creating socket: " << WSAGetLastError();
log.err("Network.Socket.winInit: Fatal error: Error creating socket");
log.err(WSAGetLastError());
WSACleanup();
return 1;
}
cout << "Network.Socket.winInit: Socket created\n";
log.info("Network.Socket.winInit: Socket created\n");
sockaddr_in service;
memset( & service, 0, sizeof(service) );
@ -32,15 +39,15 @@ public:
service.sin_addr.s_addr = inet_addr(NET_SOCK_ADDR);
service.sin_port = htons(NET_SOCK_PORT);
cout << "Network.Socket.winInit: Socket configured\n";
log.info("Network.Socket.winInit: Socket configured\n");
if (bind(mainSocket, (SOCKADDR *) & service, sizeof(service)) == SOCKET_ERROR ) {
cout << "Network.Socket.winInit: Fatal error: Bind failed\n";
log.err("Network.Socket.winInit: Fatal error: Bind failed");
closesocket(mainSocket);
return 1;
}
cout << "Network.Socket.winInit: Socket bound to address " << NET_SOCK_ADDR << " on port " << NET_SOCK_PORT << ". Ready to listen for connections\n";
log.info("Network.Socket.winInit: Socket bound to address " + NET_SOCK_ADDR + " on port " + string to_string(NET_SOCK_PORT) + ". Ready to listen for connections");
return 0;
}
@ -48,7 +55,7 @@ public:
};
int main() {
cout << "mcc v0.0.0\n";
log.raw("mcc v0.0.0");
Network::Socket socket;
socket.winInit();