Skip to content

Commit

Permalink
updated logging in example tools
Browse files Browse the repository at this point in the history
  • Loading branch information
brichards64 committed Jan 2, 2024
1 parent e3a5dab commit 017b6fe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
38 changes: 35 additions & 3 deletions UserTools/DummyTool/DummyTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,53 @@ bool DummyTool::Initialise(std::string configfile, DataModel &data){

if(!m_variables.Get("verbose",m_verbose)) m_verbose=1;

Log("test 1",1,m_verbose);
Log("test 1",1);

return true;
}


bool DummyTool::Execute(){

// example of print out methods
// mesage level indicates the minimum verbosity level to print out a message
// Therefore a message level of 0 is always printed so should be used for high priority messages e.g. errors
// and a message level or 9 would be for minor messgaes rarely printed

Log("test 2a"); // defualt log function message level is 0
*m_log<<"test 2b"<<std::endl; // defualt stream message level is 0

*m_log<<"m_verbose = "<<m_verbose<<std::endl; // Prints current verbosity level

// To create a printout for a higher level can do the following
Log("test 3a",2); // will only print if m_verbose is equal to or higher than 2
*m_log<<ML(2)<<"test 3b"<<std::endl; // note: steam message level persists and is not automatically reset

Log("test 2",2,m_verbose);
// sleep(2);
*m_log<<"test 4"<<std::endl; // Still message level 2

// This can be fixed by a message level clear function MLC();
MLC(); // call message level clear function;
*m_log<<"test 5"<<std::endl; // back to message level 0

// whilst it's possible to change the value of m_verbose for the tool as a whole
// you can also manually change it for a single message call if needed (not best practice so avoid if possible)
int tmp_verbosity=4;
Log("test 6a",2,tmp_verbosity);
*m_log<<MsgL(2,m_verbose)<<"test 6b"<<std::endl;
MLC();

// logging stream also allows for an array of colours which will automatically clear after ending the line
*m_log<<red<<"red, "<<"still red, "<<green<<"green, "<<plain<<"no colour, "<<purple<<"purple"<<std::endl;
*m_log<<"no colour"<<std::endl;


return true;
}


bool DummyTool::Finalise(){

Log("test 11",1);

return true;
}
3 changes: 1 addition & 2 deletions UserTools/DummyTool/DummyTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*
* $Author: B.Richards $
* $Date: 2019/05/28 10:44:00 $
* Contact: [email protected]
*/

class DummyTool: public Tool {


Expand All @@ -28,7 +28,6 @@ class DummyTool: public Tool {

private:

int m_verbose;

};

Expand Down
6 changes: 3 additions & 3 deletions UserTools/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool Logger::Initialise(std::string configfile, DataModel &data){

std::stringstream tmp;
tmp<<"tcp://*:"<<m_log_port;
std::cout<<"connection address = "<<tmp.str()<<std::endl;
*m_log<<"connection address = "<<tmp.str()<<std::endl;
//LogReceiver->bind(tmp.str().c_str());
// LogReceiver->setsockopt(ZMQ_SUBSCRIBE,"");
LogReceiver->bind(tmp.str().c_str());
Expand Down Expand Up @@ -48,13 +48,13 @@ bool Logger::Execute(){
// printf("got a message \n");
std::istringstream ss(static_cast<char*>(Rmessage.data()));

std::cout<<ss.str()<<std::flush;
*m_log<<ss.str()<<std::flush;

Store bb;

bb.JsonParser(ss.str());

std::cout<<*(bb["msg_value"])<<std::flush;
*m_log<<*(bb["msg_value"])<<std::flush;
}
}

Expand Down
9 changes: 5 additions & 4 deletions UserTools/template/MyToolZMQMultiThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool MyToolZMQMultiThread::Execute(){
zmq::message_t message;
ManagerReceive->recv(&message);
std::istringstream iss(static_cast<char*>(message.data()));
std::cout<<"reply = "<<iss.str()<<std::endl;
*m_log<<"reply = "<<iss.str()<<std::endl;
m_freethreads++;

}
Expand All @@ -97,9 +97,10 @@ bool MyToolZMQMultiThread::Execute(){

}

std::cout<<"free threads="<<m_freethreads<<":"<<args.size()<<std::endl;
sleep(1);
return true;
*m_log<<ML(1)<<"free threads="<<m_freethreads<<":"<<args.size()<<std::endl;
MLC();

// sleep(1); for single tool testing return true;
}


Expand Down

0 comments on commit 017b6fe

Please sign in to comment.