Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
log_capture.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <mutex>
5#include <streambuf>
6#include <string>
7
12public:
13 explicit StreamCapture(std::function<void(const std::string& line)> onLine);
15
16 StreamCapture(const StreamCapture&) = delete;
18
19private:
20 class TeeBuf : public std::streambuf {
21 public:
22 TeeBuf(std::streambuf* original, std::function<void(const std::string& line)> onLine);
23
24 protected:
25 int overflow(int ch) override;
26 int sync() override;
27
28 private:
29 std::streambuf* original_;
30 std::function<void(const std::string& line)> onLine_;
31 std::string pending_;
32 };
33
34 std::function<void(const std::string& line)> onLine_;
35 TeeBuf coutBuf_;
36 TeeBuf cerrBuf_;
37 std::streambuf* oldCout_;
38 std::streambuf* oldCerr_;
39};
Tee std::cout and std::cerr into a callback while active (one instance per thread).
Definition log_capture.h:11
StreamCapture & operator=(const StreamCapture &)=delete
~StreamCapture()
Definition log_capture.cpp:53
StreamCapture(const StreamCapture &)=delete