-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogLimitValue.cpp
More file actions
51 lines (41 loc) · 1.02 KB
/
LogLimitValue.cpp
File metadata and controls
51 lines (41 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Copyright © 2017 Matt Robinson
* Copyright © 2021 Mattias Jonsson
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <sstream>
#include "LogLimitValue.h"
const std::chrono::seconds MAX_NUM_LOG_FREQ(60);
LogFunction LogLimitValue::LogFunc;
void LogLimitValue::WriteLog(const std::string &value)
{
std::ostringstream output;
output << name << "=" << value;
LogFunc(output.str());
logCount++;
}
LogLimitValue::LogLimitValue(const std::string &name, const std::string &value) :
name(name),
lastValue(value),
started(std::chrono::steady_clock::now()),
logCount(0),
// Names for numeric values have units in square brackets
isNumeric(name.find('[') != std::string::npos)
{
WriteLog(value);
};
void LogLimitValue::NewValue(const std::string &value)
{
if(value == lastValue)
{
return;
}
if(isNumeric &&
(std::chrono::steady_clock::now() - started) / logCount < MAX_NUM_LOG_FREQ)
{
return;
}
WriteLog(value);
lastValue = value;
}