Skip to content

Commit a3aff12

Browse files
authored
Merge pull request #70 from sy-c/master
v0.21.0
2 parents 70defbe + 977e138 commit a3aff12

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ endif()
2626

2727
# Define project
2828
project(ALF
29-
VERSION 0.20.0
29+
VERSION 0.21.0
3030
DESCRIPTION "O2 ALF"
3131
LANGUAGES CXX
3232
)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ o2-alf --dim-dns-node thedimdns.cern.ch
1919
DIM_DNS_NODE=thedimdns.cern.ch
2020
`
2121

22+
Some extra parameters can be given on the command line (see `o2-alf --help`).
23+
In particular, the --dim-log-file parameter allows to define a local log file to keep track of all RPC calls received by ALF. A max file size and number of files to rotate can optionnaly be specified (comma-separated list, eg `--dim-log-file=/tmp/alf.log,1000000,4` would limit to max 4 logs file of 1000000 bytes each).
24+
25+
26+
2227
### o2-alf-client
2328
o2-alf-client is the binary of an ALF client used solely for testing purposes. On top of the DIM Nameserver it expects the hostname of the node hosting the ALF server, the card's serial and endpoint, and the link number as command-line arguments. Different arguments to test different types of services are available (run with `--help`).
2429

apps/Alf.cxx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include "ReadoutCard/Exception.h"
3131
#include "ReadoutCard/FirmwareChecker.h"
3232

33+
#include <Common/SimpleLog.h>
34+
extern SimpleLog alfDebugLog;
35+
3336
namespace ip = boost::asio::ip;
3437
namespace po = boost::program_options;
3538

@@ -55,6 +58,9 @@ class Alf : public AliceO2::Common::Program
5558
options.add_options()("dim-dns-node",
5659
po::value<std::string>(&mOptions.dimDnsNode)->default_value(""),
5760
"The DIM DNS node to set the env var if not already set");
61+
options.add_options()("dim-log-file",
62+
po::value<std::string>(&mOptions.dimLogFileConfig)->default_value(""),
63+
"Sets the log file to track DIM callbacks: filePath,maxSize,rotateCount");
5864
options.add_options()("no-fw-check",
5965
po::bool_switch(&mOptions.noFirmwareCheck)->default_value(false),
6066
"Disable firmware compatibility check");
@@ -73,6 +79,42 @@ class Alf : public AliceO2::Common::Program
7379
Logger::setFacility("ALF");
7480
Logger::get() << "ALF server starting..." << LogInfoOps_(5000) << endm;
7581

82+
if (mOptions.dimLogFileConfig!="") {
83+
std::string path;
84+
unsigned long maxBytes = 0; // default if missing
85+
unsigned int maxFiles = 0; // default if missing
86+
87+
size_t start = 0;
88+
size_t comma = mOptions.dimLogFileConfig.find(',');
89+
90+
// ---- first (mandatory): path ----
91+
if (comma == std::string::npos) {
92+
path = mOptions.dimLogFileConfig;
93+
} else {
94+
path = mOptions.dimLogFileConfig.substr(0, comma);
95+
start = comma + 1;
96+
97+
// ---- second (optional): maxBytes ----
98+
comma = mOptions.dimLogFileConfig.find(',', start);
99+
if (comma == std::string::npos) {
100+
if (start < mOptions.dimLogFileConfig.size())
101+
maxBytes = std::stoul(mOptions.dimLogFileConfig.substr(start));
102+
} else {
103+
maxBytes = std::stoul(mOptions.dimLogFileConfig.substr(start, comma - start));
104+
start = comma + 1;
105+
106+
// ---- third (optional): maxFiles ----
107+
if (start < mOptions.dimLogFileConfig.size())
108+
maxFiles = static_cast<unsigned int>(std::stoul(mOptions.dimLogFileConfig.substr(start)));
109+
}
110+
}
111+
alfDebugLog.setLogFile(path.c_str(), maxBytes, maxFiles, 1);
112+
alfDebugLog.setOutputFormat(SimpleLog::FormatOption::ShowTimeStamp | SimpleLog::FormatOption::ShowSeveritySymbol | SimpleLog::FormatOption::ShowMessage );
113+
alfDebugLog.info("ALF starting");
114+
} else {
115+
alfDebugLog.setLogFile("/dev/null");
116+
}
117+
76118
if (mOptions.dimDnsNode != "") {
77119
Logger::get() << "Setting DIM_DNS_NODE from argument." << LogDebugDevel_(5001) << endm;
78120
Logger::get() << "DIM_DNS_NODE=" << mOptions.dimDnsNode << LogDebugDevel_(5001) << endm;
@@ -144,6 +186,8 @@ class Alf : public AliceO2::Common::Program
144186
alfServer.makeRpcServers(links, mOptions.sequentialRpcs);
145187
}
146188

189+
alfDebugLog.info("Ready on DIM DNS %s with ALF id %s", mOptions.dimDnsNode.c_str(), alfId.c_str());
190+
147191
// main thread
148192
while (!isSigInt()) {
149193
std::this_thread::sleep_for(std::chrono::seconds(1));
@@ -156,6 +200,7 @@ class Alf : public AliceO2::Common::Program
156200
bool noFirmwareCheck = false;
157201
bool sequentialRpcs = false;
158202
std::string swtWordSize = "low";
203+
std::string dimLogFileConfig = "";
159204
} mOptions;
160205
};
161206

src/DimServices/DimServices.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "DimServices/DimServices.h"
2424
#include "Logger.h"
2525

26+
#include <Common/SimpleLog.h>
27+
SimpleLog alfDebugLog;
28+
29+
2630
namespace o2
2731
{
2832
namespace alf
@@ -88,16 +92,27 @@ std::string stripPrefix(const std::string& str)
8892
return str.substr(PREFIX_LENGTH);
8993
}
9094

95+
// trim a string in place
96+
inline void rtrim(std::string &s) {
97+
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
98+
return !std::isspace(ch);
99+
}).base(), s.end());
100+
}
101+
91102
void StringRpcServer::rpcHandler()
92103
{
104+
alfDebugLog.info("Request received on %s : %s",mServiceName.c_str(),getString());
93105
try {
94106
auto returnValue = mCallback(std::string(getString()));
95107
setDataString(makeSuccessString(returnValue), *this);
108+
rtrim(returnValue);
109+
alfDebugLog.info("Request completed: %s", returnValue.c_str());
96110
} catch (const std::exception& e) {
97111
if (kDebugLogging) {
98112
Logger::get() << mServiceName << ": " << e.what() << LogErrorDevel_(5100) << endm;
99113
}
100114
setDataString(makeFailureString(e.what()), *this);
115+
alfDebugLog.error("Request failure: %s", e.what());
101116
}
102117
}
103118

0 commit comments

Comments
 (0)