Skip to content

Commit

Permalink
Merge pull request #143 from art-daq/rrivera/reducingVerboseLogging
Browse files Browse the repository at this point in the history
Reducing verbose logging
  • Loading branch information
ron003 committed Mar 2, 2024
2 parents 191bf88 + 0f288e9 commit b11dc84
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 94 deletions.
44 changes: 22 additions & 22 deletions otsdaq/FECore/FEVInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ std::string FEVInterface::receiveFromFrontEnd(const std::string& requester, unsi
// macroStruct_t constructor
FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
{
__COUTV__(macroString);
__COUTVS__(20,macroString);

// example macro string:
// {"name":"testPublic","sequence":"0:w:1001:writeVal,1:r:1001:","time":"Sat Feb 0
Expand All @@ -1015,7 +1015,7 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
std::vector<std::string> extractVec;
StringMacros::getVectorFromString(macroString, extractVec, {'"'});

__COUTV__(StringMacros::vectorToString(extractVec, " ||| "));
__COUTVS__(20,StringMacros::vectorToString(extractVec, " ||| "));

enum
{
Expand Down Expand Up @@ -1044,30 +1044,30 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
__SS_THROW__;
}
macroName_ = extractVec[MACRONAME_VALUE_INDEX];
__COUTV__(macroName_);
__COUTVS__(20,macroName_);
lsbf_ = extractVec[LSFBF_VALUE_INDEX] == "false" ? false : true;
__COUTV__(lsbf_);
__COUTVS__(20,lsbf_);
std::string& sequence = extractVec[SEQUENCE_VALUE_INDEX];
__COUTV__(sequence);
__COUTVS__(20,sequence);

std::vector<std::string> sequenceCommands;
StringMacros::getVectorFromString(sequence, sequenceCommands, {','});

__COUTV__(StringMacros::vectorToString(sequenceCommands, " ### "));
__COUTVS__(20,StringMacros::vectorToString(sequenceCommands, " ### "));

for(auto& command : sequenceCommands)
{
__COUTV__(command);
__COUTVS__(20,command);

// Note: the only way to distinguish between variable and data
// is hex characters or not (lower and upper case allowed for hex)

std::vector<std::string> commandPieces;
StringMacros::getVectorFromString(command, commandPieces, {':'});

__COUTV__(StringMacros::vectorToString(commandPieces, " ### "));
__COUTVS__(20,StringMacros::vectorToString(commandPieces, " ### "));

__COUTV__(commandPieces.size());
__COUTVS__(20,commandPieces.size());

// command format
// index | type | address/sleep[ms] | data
Expand Down Expand Up @@ -1102,7 +1102,7 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)

if(commandPieces[1][0] == 'r' && commandPieces.size() == 4) // read type
{
__COUT__ << "Read type found." << __E__;
TLOG_DEBUG(20) << __COUT_HDR__ << "Read type found." << __E__;
// 2: address or optional variable name
// 3: optional variable name

Expand All @@ -1122,13 +1122,13 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
commandPieces[2] = "0" + commandPieces[2];
for(unsigned int i = 0; i < commandPieces[2].size() / 2; ++i)
{
__COUTV__(commandPieces[2].size() - 2 * (i + 1));
__COUTVS__(20,commandPieces[2].size() - 2 * (i + 1));
// add one byte at a time, backwards
lsbfData += commandPieces[2][commandPieces[2].size() - 2 * (i + 1)];
lsbfData += commandPieces[2][commandPieces[2].size() - 2 * (i + 1) + 1];
__COUTV__(lsbfData);
}
__COUTV__(lsbfData);
__COUTVS__(20,lsbfData);
StringMacros::getNumber("0x" + lsbfData, readOps_.back().address_);
}
else
Expand All @@ -1137,22 +1137,22 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
else
{
readOps_.back().addressVarName_ = commandPieces[2];
__COUTV__(readOps_.back().addressVarName_);
__COUTVS__(20,readOps_.back().addressVarName_);

namesOfInputArguments_.emplace(readOps_.back().addressVarName_);
}

if(readOps_.back().dataIsVar_)
{
readOps_.back().dataVarName_ = commandPieces[3];
__COUTV__(readOps_.back().dataVarName_);
__COUTVS__(20,readOps_.back().dataVarName_);

namesOfOutputArguments_.emplace(readOps_.back().dataVarName_);
}
}
else if(commandPieces[1][0] == 'w' && commandPieces.size() == 4) // write type
{
__COUT__ << "Write type found." << __E__;
TLOG_DEBUG(20) << __COUT_HDR__ << "Write type found." << __E__;
// 2: address or optional variable name
// 3: data or optional variable name

Expand All @@ -1178,7 +1178,7 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
lsbfData += commandPieces[2][commandPieces[2].size() - 2 * (i + 1) + 1];
__COUTV__(lsbfData);
}
__COUTV__(lsbfData);
__COUTVS__(20,lsbfData);
StringMacros::getNumber("0x" + lsbfData, writeOps_.back().address_);
}
else
Expand All @@ -1187,7 +1187,7 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
else
{
writeOps_.back().addressVarName_ = commandPieces[2];
__COUTV__(writeOps_.back().addressVarName_);
__COUTVS__(20,writeOps_.back().addressVarName_);

namesOfInputArguments_.emplace(writeOps_.back().addressVarName_);
}
Expand All @@ -1202,11 +1202,11 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
commandPieces[2] = "0" + commandPieces[3];
for(unsigned int i = 0; i < commandPieces[3].size() / 2; ++i)
{
__COUTV__(commandPieces[3].size() - 2 * (i + 1));
__COUTVS__(20,commandPieces[3].size() - 2 * (i + 1));
// add one byte at a time, backwards
lsbfData += commandPieces[3][commandPieces[3].size() - 2 * (i + 1)];
lsbfData += commandPieces[3][commandPieces[3].size() - 2 * (i + 1) + 1];
__COUTV__(lsbfData);
__COUTVS__(20,lsbfData);
}
__COUTV__(lsbfData);
StringMacros::getNumber("0x" + lsbfData, writeOps_.back().data_);
Expand All @@ -1217,14 +1217,14 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
else
{
writeOps_.back().dataVarName_ = commandPieces[3];
__COUTV__(writeOps_.back().dataVarName_);
__COUTVS__(20,writeOps_.back().dataVarName_);

namesOfInputArguments_.emplace(writeOps_.back().dataVarName_);
}
}
else if(commandPieces[1][0] == 'd' && commandPieces.size() == 3) // delay type
{
__COUT__ << "Delay type found." << __E__;
TLOG_DEBUG(20) << __COUT_HDR__ << "Delay type found." << __E__;
// 2: delay[ms] or optional variable name

operations_.push_back(std::make_pair(macroStruct_t::OP_TYPE_DELAY, delayOps_.size()));
Expand All @@ -1237,7 +1237,7 @@ FEVInterface::macroStruct_t::macroStruct_t(const std::string& macroString)
else
{
delayOps_.back().delayVarName_ = commandPieces[2];
__COUTV__(delayOps_.back().delayVarName_);
__COUTVS__(20,delayOps_.back().delayVarName_);

namesOfInputArguments_.emplace(delayOps_.back().delayVarName_);
}
Expand Down
2 changes: 1 addition & 1 deletion otsdaq/Macros/CoutMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#define __COUTT__ __COUT_TYPE__(TLVL_TRACE) << __COUT_HDR__
#define __COUTV__(X) __COUT__ << QUOTE(X) << " = " << X << __E__
#define __COUTTV__(X) __COUTT__ << QUOTE(X) << " = " << X << __E__

#define __COUTVS__(LVL,X) TLOG(TLVL_DEBUG + LVL) << __COUT_HDR__ << QUOTE(X) << " = " << X << __E__

//////// ==============================================================
//////// Use __MCOUT__ for cout and Message Facility use in one line (that compiler
Expand Down
3 changes: 2 additions & 1 deletion otsdaq/TableCore/TableView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,8 @@ unsigned int TableView::getColStatus(void) const

ss << StringMacros::stackTrace() << __E__;

__SS_THROW__;
__COUT_WARN__ << ss.str();
__SS_ONLY_THROW__;
} // end getColStatus()

//==============================================================================
Expand Down
140 changes: 75 additions & 65 deletions tools/common.sh
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
#!/bin/sh
# Source this to get color code variables to use during output
# Not sure why this is encapsulated into a function...

defineColors ()
{
# Regular Colors
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;32m' # \033[0;33m Yellow -- too hard to see on white (so making green)
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
White='\033[0;37m' # White
Black=`printf '\033[0;30m'` # Black
Red=`printf '\033[0;31m'` # Red
Green=`printf '\033[0;32m'` # Green
Yellow=`printf '\033[0;32m'` # \033[0;33m Yellow -- too hard to see on white (so making green)
Blue=`printf '\033[0;34m'` # Blue
Purple=`printf '\033[0;35m'` # Purple
Cyan=`printf '\033[0;36m'` # Cyan
White=`printf '\033[0;37m'` # White

# Bold
BBlack='\033[1;30m' # Black
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
BYellow='\033[1;33m' # Yellow
BBlue='\033[1;34m' # Blue
BPurple='\033[1;35m' # Purple
BCyan='\033[1;36m' # Cyan
BWhite='\033[1;37m' # White
BBlack=`printf '\033[1;30m'` # Black
BRed=`printf '\033[1;31m'` # Red
BGreen=`printf '\033[1;32m'` # Green
BYellow=`printf '\033[1;33m'` # Yellow
BBlue=`printf '\033[1;34m'` # Blue
BPurple=`printf '\033[1;35m'` # Purple
BCyan=`printf '\033[1;36m'` # Cyan
BWhite=`printf '\033[1;37m'` # White

# Underline
UBlack='\033[4;30m' # Black
URed='\033[4;31m' # Red
UGreen='\033[4;32m' # Green
UYellow='\033[4;33m' # Yellow
UBlue='\033[4;34m' # Blue
UPurple='\033[4;35m' # Purple
UCyan='\033[4;36m' # Cyan
UWhite='\033[4;37m' # White
UBlack=`printf '\033[4;30m'` # Black
URed=`printf '\033[4;31m'` # Red
UGreen=`printf '\033[4;32m'` # Green
UYellow=`printf '\033[4;33m'` # Yellow
UBlue=`printf '\033[4;34m'` # Blue
UPurple=`printf '\033[4;35m'` # Purple
UCyan=`printf '\033[4;36m'` # Cyan
UWhite=`printf '\033[4;37m'` # White

# Background
On_Black='\033[40m' # Black
On_Red='\033[41m' # Red
On_Green='\033[42m' # Green
On_Yellow='\033[43m' # Yellow
On_Blue='\033[44m' # Blue
On_Purple='\033[45m' # Purple
On_Cyan='\033[46m' # Cyan
On_White='\033[47m' # White
On_Black=`printf '\033[40m'` # Black
On_Red=`printf '\033[41m'` # Red
On_Green=`printf '\033[42m'` # Green
On_Yellow=`printf '\033[43m'` # Yellow
On_Blue=`printf '\033[44m'` # Blue
On_Purple=`printf '\033[45m'` # Purple
On_Cyan=`printf '\033[46m'` # Cyan
On_White=`printf '\033[47m'` # White

# High Intensity
IBlack='\033[0;90m' # Black
IRed='\033[0;91m' # Red
IGreen='\033[0;92m' # Green
IYellow='\033[0;31m' #'\033[0;93m' # Yellow -- too hard to see on white (so making light red)
IBlue='\033[0;94m' # Blue
IPurple='\033[0;95m' # Purple
ICyan='\033[0;96m' # Cyan
IWhite='\033[0;97m' # White
IBlack=`printf '\033[0;90m'` # Black
IRed=`printf '\033[0;91m'` # Red
IGreen=`printf '\033[0;92m'` # Green
IYellow=`printf '\033[0;31m'` #'\033[0;93m' # Yellow -- too hard to see on white (so making light red)
IBlue=`printf '\033[0;94m'` # Blue
IPurple=`printf '\033[0;95m'` # Purple
ICyan=`printf '\033[0;96m'` # Cyan
IWhite=`printf '\033[0;97m'` # White

# Bold High Intensity
BIBlack='\033[1;90m' # Black
BIRed='\033[1;91m' # Red
BIGreen='\033[1;92m' # Green
BIYellow='\033[1;93m' # Yellow
BIBlue='\033[1;94m' # Blue
BIPurple='\033[1;95m' # Purple
BICyan='\033[1;96m' # Cyan
BIWhite='\033[1;97m' # White
BIBlack=`printf '\033[1;90m'` # Black
BIRed=`printf '\033[1;91m'` # Red
BIGreen=`printf '\033[1;92m'` # Green
BIYellow=`printf '\033[1;93m'` # Yellow
BIBlue=`printf '\033[1;94m'` # Blue
BIPurple=`printf '\033[1;95m'` # Purple
BICyan=`printf '\033[1;96m'` # Cyan
BIWhite=`printf '\033[1;97m'` # White

# High Intensity backgrounds
On_IBlack='\033[0;100m' # Black
On_IRed='\033[0;101m' # Red
On_IGreen='\033[0;102m' # Green
On_IYellow='\033[0;103m' # Yellow
On_IBlue='\033[0;104m' # Blue
On_IPurple='\033[0;105m' # Purple
On_ICyan='\033[0;106m' # Cyan
On_IWhite='\033[0;107m' # White
On_IBlack=`printf '\033[0;100m'` # Black
On_IRed=`printf '\033[0;101m'` # Red
On_IGreen=`printf '\033[0;102m'` # Green
On_IYellow=`printf '\033[0;103m'` # Yellow
On_IBlue=`printf '\033[0;104m'` # Blue
On_IPurple=`printf '\033[0;105m'` # Purple
On_ICyan=`printf '\033[0;106m'` # Cyan
On_IWhite=`printf '\033[0;107m'` # White

RstClr=`printf '\033[0m'` # Reset color
Bold=`tput bold -T xterm` # Select bold mode
DIM=`tput dim -T xterm` # Select dim (half-bright) mode
Blink=`tput blink -T xterm` # Select dim (half-bright) mode
EUNDERLINE=`tput smul -T xterm` # Enable underline mode
DUNDERLINE=`tput rmul -T xterm` # Disable underline mode
REV=`tput rev -T xterm` # Turn on reverse video mode
RstClr='\e[0m' # Reset color
#Reset=`tput init -T xterm` # Reset all
Reset=`tput init -T xterm 2>/dev/null;tput sgr0 -T xterm` # Reset all
EBold=`tput smso -T xterm` # Enter standout (bold) mode
Expand All @@ -88,11 +88,21 @@ defineColors ()

defineColors

SCRIPT_NAME=$1
out() { echo -e "${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}$(date +'%d%h%y.%T') ${IBlue}${THIS_HOST}${RstClr} ${SCRIPT_NAME}:${Cyan}${BASH_LINENO[0]}${RstClr} |${IBlack}\t${RstClr}$@${RstClr}"; }
info() { echo -e "${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}$(date +'%d%h%y.%T') ${IBlue}${THIS_HOST}${RstClr} ${SCRIPT_NAME}:${Cyan}${BASH_LINENO[0]}${RstClr} |${IBlack}\t${RstClr}${IBlue}$@${RstClr}"; }
success() { echo -e "${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}$(date +'%d%h%y.%T') ${IBlue}${THIS_HOST}${RstClr} ${SCRIPT_NAME}:${Cyan}${BASH_LINENO[0]}${RstClr} |${IBlack}\t${RstClr}${IGreen}$@${RstClr}"; }
error() { echo -e "${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}$(date +'%d%h%y.%T') ${IBlue}${THIS_HOST}${RstClr} ${SCRIPT_NAME}:${Cyan}${BASH_LINENO[0]}${RstClr} |${IBlack}\t${RstClr}${IRed}$@${RstClr}"; } >&2
warning() { echo -e "${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}$(date +'%d%h%y.%T') ${IBlue}${THIS_HOST}${RstClr} ${SCRIPT_NAME}:${Cyan}${BASH_LINENO[0]}${RstClr} |${IBlack}\t${RstClr}${IYellow}$@${RstClr}"; } >&2
die() { echo -e "${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}$(date +'%d%h%y.%T') ${IBlue}${THIS_HOST}${RstClr} ${SCRIPT_NAME}:${Cyan}${BASH_LINENO[0]}${RstClr} |${IBlack}\t${RstClr}${IRed}$@${RstClr}"; exit 1; }
#SCRIPT_NAME=$1
out() { part1="${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}" part2="${IBlue}${THIS_HOST}${RstClr}" part3="|${IBlack} ${RstClr}"; do_out TLVL_LOG "$*"; }
info() { part1="${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}" part2="${IBlue}${THIS_HOST}${RstClr}" part3="|${IBlack} ${RstClr}$IBlue"; do_out TLVL_INFO "$*"; }
success() { part1="${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}" part2="${IBlue}${THIS_HOST}${RstClr}" part3="|${IBlack} ${RstClr}$IGreen"; do_out TLVL_NOTICE "$*"; }
warning() { part1="${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}" part2="${IBlue}${THIS_HOST}${RstClr}" part3="|${IBlack} ${RstClr}$IYellow"; do_out TLVL_WARNING "$*" >&2; }
error() { part1="${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}" part2="${IBlue}${THIS_HOST}${RstClr}" part3="|${IBlack} ${RstClr}$IRed"; do_out TLVL_ERROR "$*" >&2; }
die() { part1="${RstClr}${IRed}${STARTTIME}${RstClr}-${Green}" part2="${IBlue}${THIS_HOST}${RstClr}" part3="|${IBlack} ${RstClr}$IRed"; do_out TLVL_FATAL "$*"; exit 1; }

do_out() {
tlvl=$1;shift
if hash trace_cntl >/dev/null 2>&1;then
TRACE_TIME_FMT=%d%h%y.%T TRACE_PRINT="${part1}%T $part2 %n:$Cyan${BASH_LINENO[1]}$RstClr $part3" \
trace_cntl -n`basename "${BASH_SOURCE[2]}"` -L${BASH_LINENO[1]} TRACE TLVL_LOG "$(echo -e "$*")${RstClr}"
else
echo -e "${part1}`date +%d%h%y.%T` $part2 `basename "${BASH_SOURCE[2]}"`:$Cyan${BASH_LINENO[0]}$RstClr ${part3}${*}${RstClr}"
fi
}

9 changes: 4 additions & 5 deletions tools/ots
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ "x$OTS_USER_STUB" == "x" ]; then
fi

# Get color code variables and other common utility portions of the code
source "${SCRIPT_DIR}"/common.sh ots
source "${SCRIPT_DIR}"/common.sh

function setupTrace()
{
Expand All @@ -36,11 +36,10 @@ function setupTrace()
#setup TRACE v3_13_04
#ups active
#which trace_cntl
#type toffS
#type toffS #for muting TRACE


#for muting trace
export TRACE_NAME=OTSDAQ_TRACE
#for throttling trace:
export TRACE_LIMIT_MS="0,50,50" #unlimited trace messages
#tinfo #show trace info

Expand Down Expand Up @@ -2182,7 +2181,7 @@ export -f printMainURL
#########################################################
otsActionHandler() {

info "Starting action handler on {${THIS_HOST}}..."
info "Starting action handler on ${THIS_HOST}..."

if [[ ($ISCONFIG == 1) || ("${THIS_HOST}" == "${gatewayHostname}") ]]; then
out "The script, on ${THIS_HOST}, is the gateway ots script, so it will drive the exit of ots scripts running on other hosts."
Expand Down

0 comments on commit b11dc84

Please sign in to comment.