|
@@ -1,12 +1,24 @@
|
|
|
-//
|
|
|
-// Created by staz on 1/3/21.
|
|
|
-//
|
|
|
+/**
|
|
|
+ * Copyright (c) 2021 Staz Modrzynski
|
|
|
+ *
|
|
|
+ * This library is free software; you can redistribute it and/or
|
|
|
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
+ * License as published by the Free Software Foundation; either
|
|
|
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
+ *
|
|
|
+ * This library is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
+ * Lesser General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
+ * License along with this library; if not, write to the Free Software
|
|
|
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
+ */
|
|
|
|
|
|
#ifndef WEBRTC_SERVER_LOGCOUNTER_HPP
|
|
|
#define WEBRTC_SERVER_LOGCOUNTER_HPP
|
|
|
|
|
|
-#include <plog/Util.h>
|
|
|
-#include <plog/Severity.h>
|
|
|
#include "threadpool.hpp"
|
|
|
#include "include.hpp"
|
|
|
|
|
@@ -22,26 +34,11 @@ private:
|
|
|
std::optional<invoke_future_t<void (*)()>> future;
|
|
|
public:
|
|
|
|
|
|
- LogCounter(plog::Severity severity, const std::string& text, std::chrono::seconds duration=std::chrono::seconds(1)):
|
|
|
- severity(severity), text(text), duration(duration) {}
|
|
|
-
|
|
|
- LogCounter& operator++(int) {
|
|
|
- std::lock_guard lock(mutex);
|
|
|
- count++;
|
|
|
- if (!future) {
|
|
|
- future = ThreadPool::Instance().schedule(duration, [this]() {
|
|
|
- int countCopy;
|
|
|
- {
|
|
|
- std::lock_guard lock(mutex);
|
|
|
- countCopy = count;
|
|
|
- count = 0;
|
|
|
- future = std::nullopt;
|
|
|
- }
|
|
|
- PLOG(severity) << text << ": " << countCopy << " (over " << std::chrono::duration_cast<std::chrono::seconds>(duration).count() << " seconds)";
|
|
|
- });
|
|
|
- }
|
|
|
- return *this;
|
|
|
- }
|
|
|
+ LogCounter(plog::Severity severity, const std::string& text, std::chrono::seconds duration=std::chrono::seconds(1));
|
|
|
+
|
|
|
+ ~LogCounter();
|
|
|
+
|
|
|
+ LogCounter& operator++(int);
|
|
|
};
|
|
|
}
|
|
|
|