Skip to content

Nick #14

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open

Nick #14

wants to merge 17 commits into from

Conversation

grf14003
Copy link
Owner

No description provided.

Copy link
Owner Author

@grf14003 grf14003 left a 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

"type": "PATH"
}
]
"variables": []
Copy link
Owner Author

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.

public:
string filename;
string filePath;
FILE* fp;
Copy link
Owner Author

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

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);
Copy link
Owner Author

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?

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");
Copy link
Owner Author

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

~Logger();
void writeLog(const char* fmt, ...);
static Logger* getLogger(Logger* logger);
string getPath();
Copy link
Owner Author

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


void Logger::writeLog(const char* fmt, ...) {
this->fp = fopen(this->filePath.c_str(), "a");
//if (this->logging_Level <= msg_level) {
Copy link
Owner Author

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

fprintf(this->fp, ctime(&now));
fprintf(this->fp, "\n");
fprintf(this->fp, fmt);
fprintf(this->fp, "\n");
Copy link
Owner Author

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

Logger* Logger::getLogger(Logger* logger) {
if (logger == NULL) {
logger = new Logger(1);

Copy link
Owner Author

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

Copy link
Owner Author

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

struct tm * now = localtime( & t );
char buffer [80];
strftime (buffer,80,"%Y-%m-%d-%Hhr%Mm%Ss",now);
std::string str(buffer);
Copy link
Owner Author

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


using namespace std;


Copy link
Owner Author

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.

Copy link
Owner Author

@grf14003 grf14003 left a 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


};

static Logger* logger = logger->getLogger(logger);
Copy link
Owner Author

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


string Logger::getPath() {
char buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, MAX_PATH); // Get current working directory
Copy link
Owner Author

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

~Logger();
void log(const char* fmt, ...);
static Logger* getLogger(Logger* logger);
string getPath();
Copy link
Owner Author

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

fclose(this->fp);
}

Logger* Logger::getLogger(Logger* logger) {
Copy link
Owner Author

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


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());
Copy link
Owner Author

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

Copy link
Owner Author

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!

"type": "PATH"
}
]
"variables": []
Copy link
Owner Author

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

Copy link
Owner Author

@grf14003 grf14003 left a 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


};

//static Logger* logger = logger->getLogger(logger);
Copy link
Owner Author

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

string filename;
string filePath;
FILE* fp;

Copy link
Owner Author

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

@@ -1,8 +1,9 @@

#include "AlgorithmServer.hpp"
#include <Logger.h>
#include "Logger.hpp"
Copy link
Owner Author

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.



Logger* server_Logger = server_Logger->getLogger();
Copy link
Owner Author

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

vector<Attribute> newAttribs;
//vector<Attribute>* newAttribs = new vector<Attribute>;
Copy link
Owner Author

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


Logger* thread_Logger = thread_Logger->getLogger();
Copy link
Owner Author

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

Logger::Logger(int l_Level) {
this->logging_Level = l_Level;
time_t t = time(0); // get time now
struct tm *now = localtime( & t );
Copy link
Owner Author

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

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);
Copy link
Owner Author

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


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());
Copy link
Owner Author

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!

Logger* Logger::getLogger(Logger* logger) {
if (logger == NULL) {
logger = new Logger(1);

Copy link
Owner Author

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

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants