-
Notifications
You must be signed in to change notification settings - Fork 0
Nick #14
base: dev
Are you sure you want to change the base?
Nick #14
Changes from 1 commit
b3936ca
c0b68e9
810ff1b
daa4ff9
e0b4037
f8c705d
7f6854f
d43c958
ba311d5
cabb7d4
710a12f
9de731e
6f9b08e
afceba1
edc74e0
2d08d00
b1393ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#include <time.h> | ||
#include <chrono> | ||
#include <ctime> | ||
#include <windows.h> | ||
|
||
using namespace std; | ||
|
||
|
@@ -23,11 +24,12 @@ extern class Logger { | |
~Logger(); | ||
void writeLog(string msg, int msg_level); | ||
static Logger* getLogger(Logger* logger); | ||
string getPath(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This getPath function should be static |
||
private: | ||
int logging_Level; | ||
//auto now; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this space |
||
}; | ||
|
||
|
||
static Logger* logger = logger->getLogger(logger); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this global, if we need to use the logger in the code, we can just call getLogger(). Instead, add it as a private static pointer in the class initialized to null at first. The first time getLogger is called, this private static variable will be null, so initialize it. Every other call to getLogger (after the first) will just return the pointer and NOT reinitialize it |
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
|
||
#include "AlgorithmServer.hpp" | ||
#include <Logger.h> | ||
#include "Logger.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be included in the algorithm server hpp file not the cpp file. |
||
|
||
|
||
extern Logger* logger = getLogger(logger); | ||
//extern Logger* logger = logger->getLogger(logger); | ||
AlgorithmServer::AlgorithmServer(size_t numClients) | ||
{ | ||
this->hThread = NULL; | ||
|
@@ -68,7 +68,7 @@ void AlgorithmServer::serverThreadRuntime() | |
|
||
iResult = listen(ListenSocket, SOMAXCONN); | ||
if (iResult == SOCKET_ERROR) { | ||
logger->write_log("listen failed with error\n", 1); | ||
logger->writeLog("listen failed with error\n", 1); | ||
printf("listen failed with error: %d\n", WSAGetLastError()); | ||
closesocket(ListenSocket); | ||
WSACleanup(); | ||
|
@@ -79,6 +79,7 @@ void AlgorithmServer::serverThreadRuntime() | |
// Accept a client socket | ||
while (continueThread) | ||
{ | ||
<<<<<<< HEAD | ||
<<<<<<< HEAD | ||
write_log("Listening for clients...\n", 1, logger->filename, logger); | ||
fprintf(stderr, "Listening for clients...\n"); | ||
|
@@ -87,15 +88,18 @@ void AlgorithmServer::serverThreadRuntime() | |
fprintf(stderr, "Hello new client!\n"); | ||
======= | ||
logger->write_log("Listening for clients...\n", 1); | ||
======= | ||
logger->writeLog("Listening for clients...\n", 1); | ||
>>>>>>> Reupload logger changes | ||
printf("Listening for clients...\n"); | ||
ClientSocket = accept(ListenSocket, NULL, NULL); | ||
logger->write_log("Hello new client!\n", 1); | ||
logger->writeLog("Hello new client!\n", 1); | ||
printf("Hello new client!\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this printf |
||
>>>>>>> Test log | ||
if (ClientSocket == INVALID_SOCKET) { | ||
logger->write_log("accept failed with error: ", 1); | ||
logger->write_log(std::to_string(WSAGetLastError()), 1); | ||
logger->write_log("\n", 1); | ||
logger->writeLog("accept failed with error: ", 1); | ||
logger->writeLog(std::to_string(WSAGetLastError()), 1); | ||
logger->writeLog("\n", 1); | ||
printf("accept failed with error: %d\n", WSAGetLastError()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this printf |
||
AcceptFailures++; | ||
if (AcceptFailures >= MAX_ACCEPT_FAILURES) | ||
|
@@ -134,7 +138,7 @@ void AlgorithmServer::serverThreadRuntime() | |
unlockClientThreadsMutex(); | ||
} | ||
else { | ||
logger->write_log("Could not acquire mutex to add new client thread\n", 1); | ||
logger->writeLog("Could not acquire mutex to add new client thread\n", 1); | ||
printf("Could not acquire mutex to add new client thread\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this printf |
||
} | ||
} | ||
|
@@ -172,9 +176,13 @@ vector<Attribute> AlgorithmServer::getAllIncomingAttributes() | |
} | ||
else { | ||
<<<<<<< HEAD | ||
<<<<<<< HEAD | ||
======= | ||
logger->write_log("Could not acquire mutex to add new client thread\n", 1); | ||
>>>>>>> Test log | ||
======= | ||
logger->writeLog("Could not acquire mutex to add new client thread\n", 1); | ||
>>>>>>> Reupload logger changes | ||
printf("Could not acquire mutex to get incoming attributes.\n"); | ||
} | ||
return newAttribs; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
//#include <Logger.h> | ||
#include "DataSyncThread.hpp" | ||
//include<Logger.h> | ||
#include "Logger.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, do not include things in cpp files. It should be included in the hpp file corresponding to this cpp file. |
||
|
||
|
||
//extern Logger* logger = logger->getLogger(logger); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this and all other commented out code |
||
void DataSyncThread::threadRuntime() | ||
{ | ||
threadRunning = true; | ||
|
@@ -155,6 +157,7 @@ void DataSyncThread::startComms() | |
//write_log("Start comms: ", 1, logger->filename, logger); | ||
//write_log(std::to_string(incomingAttributes), 1, logger->filename, logger); | ||
|
||
|
||
if (!threadRunning) | ||
{ | ||
threadRunning = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,23 @@ Logger::Logger(int l_Level) { | |
time_t t = time(0); // get time now | ||
struct tm * now = localtime( & t ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix spacing |
||
char buffer [80]; | ||
strftime (buffer,80,"%Y-%m-%d %H:%M:%S",now); | ||
strftime (buffer,80,"%Y-%m-%d-%Hhr%Mm%Ss",now); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the spacing between commas in the function call here |
||
std::string str(buffer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can get rid of all the std:: in this file because you have "using namespace std" in your header |
||
this->filename = str + ".log"; | ||
//cout << filename << "\n"; | ||
//this->filename = "log.txt"; | ||
this->filePath = getPath() + this->filename; // Sets location and name of log file | ||
} | ||
|
||
string Logger::getPath() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the indenting in this function and get rid of the commented out code. Also, can't this function be static? |
||
char buffer[MAX_PATH]; | ||
GetModuleFileName(NULL, buffer, MAX_PATH); // Get current working directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You still didn't fix the indenting here |
||
string::size_type pos = string(buffer).find_last_of("\\/"); | ||
string::size_type pos2 = string(buffer).substr(0, pos).find_last_of( "\\/" ); | ||
string logPath = string(buffer).substr(0, pos2) + "\\logs\\"; | ||
return logPath; | ||
} | ||
|
||
void Logger::writeLog(string msg, int msg_level) { | ||
string line; | ||
this->logFile.open(this->filename, ios::in); | ||
this->logFile.open(this->filePath, ios::app); | ||
if (this->logging_Level <= msg_level) { | ||
auto now = chrono::system_clock::to_time_t(chrono::system_clock::now()); | ||
this->logFile << ctime(&now) << " " << msg << endl; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these functions can be private I think