Skip to content

Commit 37b3e9a

Browse files
authored
[OMON-691] Use MonLogger in executables (#325)
1 parent bb82f39 commit 37b3e9a

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endif()
3131

3232
# Define project
3333
project(Monitoring
34-
VERSION 3.16.2
34+
VERSION 3.17.0
3535
DESCRIPTION "O2 Monitoring library"
3636
LANGUAGES CXX
3737
)
@@ -287,7 +287,9 @@ if(RdKafka_FOUND AND Protobuf_FOUND AND CURL_FOUND)
287287
Monitoring
288288
Boost::program_options
289289
protobuf::libprotobuf
290+
$<$<BOOL:${InfoLogger_FOUND}>:AliceO2::InfoLogger>
290291
)
292+
target_compile_definitions(${example_name} PRIVATE $<$<BOOL:${InfoLogger_FOUND}>:O2_MONITORING_WITH_INFOLOGGER>)
291293
target_include_directories(${example_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
292294
install(TARGETS ${example_name})
293295
endforeach()

examples/12-KafkaToInfluxDb.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <boost/algorithm/string.hpp>
1515

1616
#include "envs.pb.h"
17+
#include "../src/MonLogger.h"
1718

1819
using namespace o2::monitoring;
1920

@@ -51,10 +52,10 @@ int main(int argc, char* argv[])
5152
auto metric = Metric{"run_times"};
5253
if (change.first.find("leave") != std::string::npos) {
5354
metric.addValue(stateChange.timestamp(), "eor");
54-
std::cout << stateChange.envinfo().environmentid() << "/" << stateChange.envinfo().runnumber() << " " << change.first << " EOR: " << stateChange.timestamp() << std::endl;
55+
MonLogger::Get() << stateChange.envinfo().environmentid() << "/" << stateChange.envinfo().runnumber() << " " << change.first << " EOR: " << stateChange.timestamp() << MonLogger::End();
5556
} else {
5657
metric.addValue(stateChange.envinfo().runtype(), "type").addValue(stateChange.envinfo().enterstatetimestamp(), "sor");
57-
std::cout << stateChange.envinfo().environmentid() << "/" << stateChange.envinfo().runnumber() << " " << change.first << " SOR: " <<stateChange.envinfo().enterstatetimestamp() << std::endl;
58+
MonLogger::Get() << stateChange.envinfo().environmentid() << "/" << stateChange.envinfo().runnumber() << " " << change.first << " SOR: " <<stateChange.envinfo().enterstatetimestamp() << MonLogger::End();
5859
}
5960
int run = stateChange.envinfo().runnumber();
6061
if (run > 1) {

examples/14-OrbitId.cxx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <boost/algorithm/string.hpp>
1515

1616
#include "envs.pb.h"
17+
#include "../src/MonLogger.h"
1718

1819
using namespace o2::monitoring;
1920

@@ -61,11 +62,11 @@ int main(int argc, char* argv[])
6162
}
6263
}
6364
if (detectorRunMap.empty()) {
64-
std::cout << "No ongoing runs" << std::endl;
65+
MonLogger::Get() << "No ongoing runs" << MonLogger::End();
6566
referenceOrbitIdMap.clear();
6667
}
6768
for (const auto &p : detectorRunMap) {
68-
std::cout << p.first << " belongs to run " << p.second << std::endl;
69+
MonLogger::Get() << p.first << " belongs to run " << p.second << MonLogger::End();
6970
}
7071
// if SOR
7172
// handle link status messages
@@ -105,12 +106,12 @@ int main(int argc, char* argv[])
105106
continue;
106107
}
107108
referenceOrbitIdMap.insert({detectorRunMap.at(detector), orbitId});
108-
std::cout << "Set reference orbitId for run " << detectorRunMap.at(detector) << ": " << orbitId << std::endl;
109+
MonLogger::Get() << "Set reference orbitId for run " << detectorRunMap.at(detector) << ": " << orbitId << MonLogger::End();
109110
unixSocket->send(outputMetric + " reference=" + orbitId);
110111
}
111112
auto referenceOrbitId = referenceOrbitIdMap.at(detectorRunMap.at(detector));
112113
if (orbitId != referenceOrbitId) {
113-
std::cout << "Abnormal condition for " << detector << "; expected orbitID: " << referenceOrbitId << " but got: " << orbitId << std::endl;
114+
MonLogger::Get() << "Abnormal condition for " << detector << "; expected orbitID: " << referenceOrbitId << " but got: " << orbitId << MonLogger::End();
114115
unixSocket->send(outputMetric + " mismatched=" + orbitId);
115116
}
116117
}

examples/8-KafkaToHttpServer.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616

1717
#include "../src/Transports/KafkaConsumer.h"
1818
#include "envs.pb.h"
19+
#include "../src/MonLogger.h"
1920

2021
namespace beast = boost::beast;
2122
namespace http = beast::http;
2223
using tcp = boost::asio::ip::tcp;
2324
using namespace std::literals::string_literals;
24-
25+
using o2::monitoring::MonLogger;
2526

2627
aliceo2::envs::ActiveRunsList gActiveEnvs;
2728
std::mutex gEnvAccess;
@@ -198,11 +199,11 @@ void deserializeActiveRuns(const std::string& lastActiveRunMessage)
198199
aliceo2::envs::ActiveRunsList activeRuns;
199200
activeRuns.ParseFromString(lastActiveRunMessage);
200201
if (activeRuns.activeruns_size() == 0) {
201-
std::cout << "Empty active runs" << std::endl;
202+
MonLogger::Get() << "Empty active runs" << MonLogger::End();
202203
} else {
203204
for (int i = 0; i < activeRuns.activeruns_size(); i++) {
204-
std::cout << "Active run: " << activeRuns.activeruns(i).runnumber() << " ("
205-
<< activeRuns.activeruns(i).environmentid() << ")" << std::endl;
205+
MonLogger::Get() << "Active run: " << activeRuns.activeruns(i).runnumber() << " ("
206+
<< activeRuns.activeruns(i).environmentid() << ")" << MonLogger::End();
206207
}
207208
}
208209
const std::lock_guard<std::mutex> lock(gEnvAccess);
@@ -220,7 +221,7 @@ int main(int argc, char* argv[]) {
220221
boost::program_options::notify(vm);
221222
unsigned short port = vm["http-port"].as<unsigned short>();
222223

223-
std::cout << "Using Kafka instance: " << vm["kafka-host"].as<std::string>() << ":9092 and HTTP server port: " << port << std::endl;
224+
MonLogger::Get() << "Using Kafka instance: " << vm["kafka-host"].as<std::string>() << ":9092 and HTTP server port: " << port << MonLogger::End();
224225
std::thread webServerThread([&port](){
225226
auto const address = boost::asio::ip::make_address("0.0.0.0");
226227
boost::asio::io_context ioc{1};

src/MonLogger.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#define MONITORING_MONINFOLOGGER_H
1919

2020
#include <chrono>
21-
#include <iomanip>
22-
#include <iostream>
2321

2422
#ifdef O2_MONITORING_WITH_INFOLOGGER
2523
#include <InfoLogger/InfoLogger.hxx>
2624
using namespace AliceO2::InfoLogger;
25+
#else
26+
#include <iostream>
27+
#include <iomanip>
2728
#endif
2829

2930
namespace o2

0 commit comments

Comments
 (0)