-
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?
Conversation
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.
Hey Nick,
Great job on this code! You have made some excellent progress. My comments were mostly formatting things so no big deal there. I did have one major suggestion. The writeLog function should also print to stdout. I talk about it more in my line comments but its probably my fault. I should have been more clear when I was describing the purpose of this function to you. Anyways, let me know if you have any questions and push your changes when you make the edits I suggested. Don't merge yet though!
Best regards,
Greg
bfs/CMakeSettings.json
Outdated
"type": "PATH" | ||
} | ||
] | ||
"variables": [] |
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.
Get rid of this change, you should not need to edit this file.
bfs/include/Logger.hpp
Outdated
public: | ||
string filename; | ||
string filePath; | ||
FILE* fp; |
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.
fp, filename, and filepath should all be private
bfs/src/comms/AlgorithmServer.cpp
Outdated
write_log("Listening for clients...\n", 1, logger->filename, logger); | ||
fprintf(stderr, "Listening for clients...\n"); | ||
logger->writeLog("Listening for clients...\n"); | ||
logger->writeLog("%s", logger->filePath); |
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.
You can just combine this line into the previous one right?
bfs/src/comms/AlgorithmServer.cpp
Outdated
write_log("Hello new client!\n", 1, logger->filename, logger); | ||
fprintf(stderr, "Hello new client!\n"); | ||
logger->writeLog("Hello new client!\n"); | ||
printf("Hello new client!\n"); |
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.
Get rid of this printf
bfs/include/Logger.hpp
Outdated
~Logger(); | ||
void writeLog(const char* fmt, ...); | ||
static Logger* getLogger(Logger* logger); | ||
string getPath(); |
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
bfs/src/logging/Logger.cpp
Outdated
|
||
void Logger::writeLog(const char* fmt, ...) { | ||
this->fp = fopen(this->filePath.c_str(), "a"); | ||
//if (this->logging_Level <= msg_level) { |
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.
Get rid of all the commented out code in this function
bfs/src/logging/Logger.cpp
Outdated
fprintf(this->fp, ctime(&now)); | ||
fprintf(this->fp, "\n"); | ||
fprintf(this->fp, fmt); | ||
fprintf(this->fp, "\n"); |
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.
All these fprintf statements can be compacted into one line
bfs/src/logging/Logger.cpp
Outdated
Logger* Logger::getLogger(Logger* logger) { | ||
if (logger == NULL) { | ||
logger = new Logger(1); | ||
|
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.
Get rid of this space
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.
Still need to do this
bfs/src/logging/Logger.cpp
Outdated
struct tm * now = localtime( & t ); | ||
char buffer [80]; | ||
strftime (buffer,80,"%Y-%m-%d-%Hhr%Mm%Ss",now); | ||
std::string str(buffer); |
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.
You can get rid of all the std:: in this file because you have "using namespace std" in your header
bfs/include/Logger.hpp
Outdated
|
||
using namespace std; | ||
|
||
|
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.
Too much space here, I know it seems kinda picky but there should just be one.
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.
Hey Nick, Still a couple more things to fix. I tried to explain it better this time because maybe I was a little vague in my last set of comments. You also need to rebase your branch to dev before you cal merge the pull request. Also, don't merge until a approve it.
Best regards,
Greg
bfs/include/Logger.hpp
Outdated
|
||
}; | ||
|
||
static Logger* logger = logger->getLogger(logger); |
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.
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
bfs/src/logging/Logger.cpp
Outdated
|
||
string Logger::getPath() { | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
You still didn't fix the indenting here
bfs/include/Logger.hpp
Outdated
~Logger(); | ||
void log(const char* fmt, ...); | ||
static Logger* getLogger(Logger* logger); | ||
string getPath(); |
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.
This getPath function should be static
bfs/src/logging/Logger.cpp
Outdated
fclose(this->fp); | ||
} | ||
|
||
Logger* Logger::getLogger(Logger* logger) { |
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.
You don't have to pass the logger pointer here, just use the global
bfs/src/logging/Logger.cpp
Outdated
|
||
void Logger::log(const char* fmt, ...) { | ||
this->fp = fopen(this->filePath.c_str(), "a"); | ||
auto now = chrono::system_clock::to_time_t(chrono::system_clock::now()); |
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.
If you are going to use auto here, add a comment to say what the type is that is returning
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.
Still need to do this!
bfs/CMakeSettings.json
Outdated
"type": "PATH" | ||
} | ||
] | ||
"variables": [] |
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.
You still need to get rid of this change
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.
Hey Nick,
Good job fixing some things. Still a couple of small things to fix. There are still some globals to remove. Rather that using global variables in the data sync thread and algorithm server, just call getLogger any time you need it in the code rather than referencing the global.
There are also some conflicts so you have to rebase to the latest dev before you can merge. If you have questions about this, ask on WA or ask on WA if I am available to chat on discord.
There are also some things that it looks like you missed in my last review so make sure you address those this time. Hopefully we can get this merged by EOD today.
Best regards and happy editing,
Greg
bfs/include/Logger.hpp
Outdated
|
||
}; | ||
|
||
//static Logger* logger = logger->getLogger(logger); |
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.
Get rid of this comment
bfs/include/Logger.hpp
Outdated
string filename; | ||
string filePath; | ||
FILE* fp; | ||
|
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.
Get rid of this space
bfs/src/comms/AlgorithmServer.cpp
Outdated
@@ -1,8 +1,9 @@ | |||
|
|||
#include "AlgorithmServer.hpp" | |||
#include <Logger.h> | |||
#include "Logger.hpp" |
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.
This should be included in the algorithm server hpp file not the cpp file.
bfs/src/comms/AlgorithmServer.cpp
Outdated
|
||
|
||
Logger* server_Logger = server_Logger->getLogger(); |
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.
This is a global variable when located right here and should be removed
bfs/src/comms/AlgorithmServer.cpp
Outdated
vector<Attribute> newAttribs; | ||
//vector<Attribute>* newAttribs = new vector<Attribute>; |
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.
Still need to get rid of this
bfs/src/comms/DataSyncThread.cpp
Outdated
|
||
Logger* thread_Logger = thread_Logger->getLogger(); |
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.
Same as above. Global variables are bad! Get rid of this
bfs/src/logging/Logger.cpp
Outdated
Logger::Logger(int l_Level) { | ||
this->logging_Level = 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of the spacing in the &t at the end of this line
bfs/src/logging/Logger.cpp
Outdated
time_t t = time(0); // get time now | ||
struct tm *now = localtime( & t ); | ||
char buffer [80]; | ||
strftime (buffer, 80, "%Y-%m-%d-%Hhr%Mm%Ss", now); |
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.
This time format string: "%Y-%m-%d-%Hhr%Mm%Ss" should be a private const variable in the logger class
bfs/src/logging/Logger.cpp
Outdated
|
||
void Logger::log(const char* fmt, ...) { | ||
this->fp = fopen(this->filePath.c_str(), "a"); | ||
auto now = chrono::system_clock::to_time_t(chrono::system_clock::now()); |
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.
Still need to do this!
bfs/src/logging/Logger.cpp
Outdated
Logger* Logger::getLogger(Logger* logger) { | ||
if (logger == NULL) { | ||
logger = new Logger(1); | ||
|
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.
Still need to do this
No description provided.