Skip to content

Commit

Permalink
[alf] Disable debug logging by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kostorr committed Dec 1, 2021
1 parent bd66b65 commit a8ebf15
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 27 deletions.
2 changes: 1 addition & 1 deletion apps/Alf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Alf : public AliceO2::Common::Program

virtual void run(const po::variables_map&) override
{
//verbose = isVerbose();
kDebugLogging = isVerbose();

Logger::setFacility("ALF");
Logger::get() << "ALF server starting..." << LogInfoOps << endm;
Expand Down
2 changes: 2 additions & 0 deletions apps/AlfClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class AlfClient : public AliceO2::Common::Program

virtual void run(const po::variables_map&) override
{
kDebugLogging = isVerbose();

Logger::enableInfoLogger(false);
Logger::setFacility("ALF/Client");
if (mOptions.alfId == "") {
Expand Down
2 changes: 2 additions & 0 deletions apps/AlfLibClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class AlfLibClient : public AliceO2::Common::Program

virtual void run(const po::variables_map&) override
{
kDebugLogging = isVerbose();

Logger::enableInfoLogger(false);
Logger::setFacility("ALF/LibClient");
if (mOptions.sca) {
Expand Down
40 changes: 30 additions & 10 deletions src/AlfClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class RegisterReadRpc : DimRpcInfoWrapper
toConvert = stripPrefix(getString());
converted = Util::stringToHex(toConvert);
} catch (const AlfException& e) {
Logger::get() << "RegisterReadRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "RegisterReadRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errHex;
}

Expand All @@ -74,7 +76,9 @@ class RegisterWriteRpc : DimRpcInfoWrapper
try {
getString();
} catch (const AlfException& e) {
Logger::get() << "RegisterWriteRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "RegisterWriteRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
}
}
};
Expand All @@ -93,7 +97,9 @@ class PatternPlayerRpc : DimRpcInfoWrapper
try {
ret = getString();
} catch (const AlfException& e) {
Logger::get() << "PatternPlayerRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "PatternPlayerRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errString;
}
return ret;
Expand Down Expand Up @@ -127,7 +133,9 @@ class ScaSequenceRpc : DimRpcInfoWrapper
try {
ret = getString();
} catch (const AlfException& e) {
Logger::get() << "ScaSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "ScaSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errString;
}
return ret;
Expand Down Expand Up @@ -165,7 +173,9 @@ class RegisterSequenceRpc : DimRpcInfoWrapper
try {
ret = getString();
} catch (const AlfException& e) {
Logger::get() << "RegisterSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "RegisterSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errString;
}
return ret;
Expand Down Expand Up @@ -203,7 +213,9 @@ class SwtSequenceRpc : DimRpcInfoWrapper
try {
ret = getString();
} catch (const AlfException& e) {
Logger::get() << "SwtSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "SwtSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errString;
}
return ret;
Expand Down Expand Up @@ -241,7 +253,9 @@ class IcSequenceRpc : DimRpcInfoWrapper
try {
ret = getString();
} catch (const AlfException& e) {
Logger::get() << "IcSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "IcSequence: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errString;
}
return ret;
Expand Down Expand Up @@ -278,7 +292,9 @@ class IcGbtI2cWriteRpc : DimRpcInfoWrapper
try {
getString();
} catch (const AlfException& e) {
Logger::get() << "IcGbtI2cWriteRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "IcGbtI2cWriteRpc: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
}
}
};
Expand All @@ -298,7 +314,9 @@ class LlaSessionStartRpc : DimRpcInfoWrapper
try {
ret = getString();
} catch (const AlfException& e) {
Logger::get() << "LlaSessionStart: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "LlaSessionStart: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errString;
}
return ret;
Expand Down Expand Up @@ -331,7 +349,9 @@ class LlaSessionStopRpc : DimRpcInfoWrapper
try {
ret = getString();
} catch (const AlfException& e) {
Logger::get() << "LlaSessionStop: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << "LlaSessionStop: " << boost::diagnostic_information(e, true) << LogErrorDevel << endm;
}
return errString;
}
return ret;
Expand Down
4 changes: 3 additions & 1 deletion src/DimServices/DimServices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ void StringRpcServer::rpcHandler()
auto returnValue = mCallback(std::string(getString()));
setDataString(makeSuccessString(returnValue), *this);
} catch (const std::exception& e) {
Logger::get() << mServiceName << ": " << e.what() << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << mServiceName << ": " << e.what() << LogErrorDevel << endm;
}
setDataString(makeFailureString(e.what()), *this);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DimServices/DimServices.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class DimRpcInfoWrapper
std::string getString()
{
auto str = std::string(mRpcInfo->getString());
if (isFailure(str)) {
if (isFailure(str) && kDebugLogging) {
Logger::get() << "ALF server failure: " << str << LogErrorDevel << endm;
}
return str;
Expand Down
16 changes: 12 additions & 4 deletions src/Ic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ namespace alf
Ic::Ic(AlfLink link, std::shared_ptr<lla::Session> llaSession)
: ScBase(link, llaSession)
{
Logger::setFacility("ALF/IC");
if (kDebugLogging) {
Logger::setFacility("ALF/IC");
}

// Set CFG to 0x3 by default
barWrite(sc_regs::IC_WR_CFG.index, 0x3);
Expand All @@ -57,7 +59,9 @@ Ic::Ic(AlfLink link, std::shared_ptr<lla::Session> llaSession)
Ic::Ic(const roc::Parameters::CardIdType& cardId, int linkId)
: ScBase(cardId, linkId)
{
Logger::setFacility("ALF/IC");
if (kDebugLogging) {
Logger::setFacility("ALF/IC");
}

// Set CFG to 0x3 by default
barWrite(sc_regs::IC_WR_CFG.index, 0x3);
Expand All @@ -66,7 +70,9 @@ Ic::Ic(const roc::Parameters::CardIdType& cardId, int linkId)
Ic::Ic(std::string cardId, int linkId)
: ScBase(cardId, linkId)
{
Logger::setFacility("ALF/IC");
if (kDebugLogging) {
Logger::setFacility("ALF/IC");
}

// Set CFG to 0x3 by default
barWrite(sc_regs::IC_WR_CFG.index, 0x3);
Expand Down Expand Up @@ -204,7 +210,9 @@ std::string Ic::writeSequence(std::vector<std::pair<Operation, Data>> ops, bool
} else if (operation == Operation::Error) {
std::string errMessage = boost::get<std::string>(data);
resultBuffer << errMessage;
Logger::get() << errMessage << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << errMessage << LogErrorDevel << endm;
}
BOOST_THROW_EXCEPTION(IcException() << ErrorInfo::Message(resultBuffer.str()));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
typedef AliceO2::roc::Logger Logger;
constexpr auto endm = AliceO2::roc::endm;

extern bool kDebugLogging;

#endif // O2_ALF_LOGGER_H_
3 changes: 3 additions & 0 deletions src/ScBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "Logger.h"
#include "Util.h"

// hijacking this file to define an extern variable for the Logger
bool kDebugLogging;

namespace sc_regs = AliceO2::roc::Cru::ScRegisters;

namespace o2
Expand Down
16 changes: 12 additions & 4 deletions src/Sca.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,25 @@ namespace alf
Sca::Sca(AlfLink link, std::shared_ptr<lla::Session> llaSession)
: ScBase(link, llaSession)
{
Logger::setFacility("ALF/SCA");
if (kDebugLogging) {
Logger::setFacility("ALF/SCA");
}
}

Sca::Sca(const roc::Parameters::CardIdType& cardId, int linkId)
: ScBase(cardId, linkId)
{
Logger::setFacility("ALF/SCA");
if (kDebugLogging) {
Logger::setFacility("ALF/SCA");
}
}

Sca::Sca(std::string cardId, int linkId)
: ScBase(cardId, linkId)
{
Logger::setFacility("ALF/SCA");
if (kDebugLogging) {
Logger::setFacility("ALF/SCA");
}
}

void Sca::svlReset()
Expand Down Expand Up @@ -304,7 +310,9 @@ std::string Sca::writeSequence(const std::vector<std::pair<Operation, Data>>& op
resultBuffer << "svl_connect\n"; // echo
} else if (operation == Operation::Error) {
resultBuffer << data; // "[error_msg]"
Logger::get() << data << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << data << LogErrorDevel << endm;
}
BOOST_THROW_EXCEPTION(ScaException() << ErrorInfo::Message(resultBuffer.str()));
break;
}
Expand Down
8 changes: 6 additions & 2 deletions src/ScaMftPsu.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ namespace alf
ScaMftPsu::ScaMftPsu(AlfLink link, std::shared_ptr<lla::Session> llaSession)
: mLink(link), mBar2(mLink.bar)
{
Logger::setFacility("ALF/SCA_MFT_PSU");
if (kDebugLogging) {
Logger::setFacility("ALF/SCA_MFT_PSU");
}
mLlaSession = std::make_unique<LlaSession>(llaSession);
mLink.rawLinkId = mLink.serialId.getEndpoint() * kCruNumLinks + mLink.linkId;
}
Expand Down Expand Up @@ -326,7 +328,9 @@ std::string ScaMftPsu::writeSequence(const std::vector<std::pair<Operation, Data
resultBuffer << "slave\n"; // echo
} else if (operation == Operation::Error) {
resultBuffer << data; // "[error_msg]"
Logger::get() << data << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << data << LogErrorDevel << endm;
}
BOOST_THROW_EXCEPTION(ScaMftPsuException() << ErrorInfo::Message(resultBuffer.str()));
break;
}
Expand Down
16 changes: 12 additions & 4 deletions src/Swt.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,25 @@ namespace sc_regs = AliceO2::roc::Cru::ScRegisters;
Swt::Swt(AlfLink link, std::shared_ptr<lla::Session> llaSession)
: ScBase(link, llaSession)
{
Logger::setFacility("ALF/SWT");
if (kDebugLogging) {
Logger::setFacility("ALF/SWT");
}
}

Swt::Swt(const roc::Parameters::CardIdType& cardId, int linkId)
: ScBase(cardId, linkId)
{
Logger::setFacility("ALF/SWT");
if (kDebugLogging) {
Logger::setFacility("ALF/SWT");
}
}

Swt::Swt(std::string cardId, int linkId)
: ScBase(cardId, linkId)
{
Logger::setFacility("ALF/SWT");
if (kDebugLogging) {
Logger::setFacility("ALF/SWT");
}
}

std::vector<SwtWord> Swt::read(SwtWord::Size wordSize, TimeOut msTimeOut)
Expand Down Expand Up @@ -210,7 +216,9 @@ std::string Swt::writeSequence(std::vector<std::pair<Operation, Data>> sequence,
resultBuffer << std::dec << data << "\n";
} else if (operation == Operation::Error) {
resultBuffer << data;
Logger::get() << data << LogErrorDevel << endm;
if (kDebugLogging) {
Logger::get() << data << LogErrorDevel << endm;
}
BOOST_THROW_EXCEPTION(SwtException() << ErrorInfo::Message(resultBuffer.str()));
break;
}
Expand Down

0 comments on commit a8ebf15

Please sign in to comment.