Skip to content

Commit 98960a0

Browse files
authored
Do not use MonLogger in StdOut backend (#85)
1 parent d043329 commit 98960a0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Backends/StdOut.cxx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
///
55

66
#include "StdOut.h"
7-
8-
#include <iostream>
97
#include "../MonLogger.h"
8+
#include <iostream>
109

1110
namespace o2
1211
{
@@ -24,7 +23,7 @@ inline unsigned long StdOut::convertTimestamp(const std::chrono::time_point<std:
2423
).count();
2524
}
2625

27-
StdOut::StdOut()
26+
StdOut::StdOut() : mStream(std::cout)
2827
{
2928
setVerbosisty(backend::Verbosity::Debug);
3029
MonLogger::Get() << "StdOut backend initialized" << MonLogger::End();
@@ -57,9 +56,11 @@ void StdOut::sendMultiple(std::string measurement, std::vector<Metric>&& metrics
5756
if (!metricTags.empty()) {
5857
metricTags = "," + metricTags;
5958
}
60-
MonLogger::Get() << "[METRIC] " << measurement << "/" << metric.getName() << "," << metric.getType() << " "
61-
<< metric.getValue() << " " << convertTimestamp(metric.getTimestamp()) << " " << tagString << metricTags
62-
<< MonLogger::End();
59+
auto tStamp = std::chrono::system_clock::to_time_t(metric.getTimestamp());
60+
mStream << std::put_time(std::localtime(&tStamp), "%Y-%m-%d %X") << "\t"
61+
<< "[METRIC] " << measurement << "/" << metric.getName() << "," << metric.getType() << " "
62+
<< metric.getValue() << " " << convertTimestamp(metric.getTimestamp()) << " " << tagString
63+
<< metricTags << "\n";
6364
}
6465
}
6566

@@ -75,9 +76,11 @@ void StdOut::send(const Metric& metric)
7576
if (!metricTags.empty()) {
7677
metricTags = "," + metricTags;
7778
}
78-
MonLogger::Get() << "[METRIC] " << metric.getName() << "," << metric.getType() << " " << metric.getValue()
79+
auto tStamp = std::chrono::system_clock::to_time_t(metric.getTimestamp());
80+
mStream << std::put_time(std::localtime(&tStamp), "%Y-%m-%d %X") << "\t"
81+
<< "[METRIC] " << metric.getName() << "," << metric.getType() << " " << metric.getValue()
7982
<< " " << convertTimestamp(metric.getTimestamp()) << " " << tagString << metricTags
80-
<< MonLogger::End();
83+
<< "\n";
8184
}
8285

8386
} // namespace backends

src/Backends/StdOut.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class StdOut final : public Backend
4949
void addGlobalTag(std::string name, std::string value) override;
5050

5151
private:
52+
/// Metric stream
53+
std::ostream &mStream;
54+
5255
/// Converts timestamp to unsigned long (miliseconds from epoch)
5356
/// \param timestamp timestamp in std::chrono::time_point format
5457
/// \return timestamp as unsigned long (miliseconds from epoch)

0 commit comments

Comments
 (0)