MeshLib Documentation
Loading...
Searching...
No Matches
MRRestoringStreamsSink.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRPch/MRSpdlog.h"
5#include <mutex>
6#include <streambuf>
7#include <string>
8
9namespace MR
10{
11
14
16class LoggingStreambuf : public std::streambuf
17{
18public:
19 MRMESH_API explicit LoggingStreambuf( spdlog::level::level_enum level );
20
21protected:
22 MRMESH_API std::streamsize xsputn( const char_type* s, std::streamsize count ) override;
23 MRMESH_API int_type overflow( int_type ch = traits_type::eof() ) override;
24
25private:
27 spdlog::level::level_enum level_;
28 std::mutex bufMutex_;
29 std::string buf_;
30};
31
34class RestoringStreamsSink : public spdlog::sinks::base_sink<spdlog::details::null_mutex>
35{
36public:
39
40private:
41 virtual void sink_it_( const spdlog::details::log_msg& ) override { }
42 virtual void flush_() override { }
43
44 std::streambuf* coutBuf_;
45 std::streambuf* cerrBuf_;
46 std::streambuf* clogBuf_;
47
48 LoggingStreambuf spdCoutBuf_;
49 LoggingStreambuf spdCerrBuf_;
50 LoggingStreambuf spdClogBuf_;
51};
52
56
58
59} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
A custom streambuf that outputs things directly to the default spdlog logger.
Definition MRRestoringStreamsSink.h:17
MRMESH_API std::streamsize xsputn(const char_type *s, std::streamsize count) override
MRMESH_API int_type overflow(int_type ch=traits_type::eof()) override
MRMESH_API LoggingStreambuf(spdlog::level::level_enum level)
Definition MRRestoringStreamsSink.h:35
MRMESH_API ~RestoringStreamsSink()
MRMESH_API RestoringStreamsSink()
MRMESH_API void redirectSTDStreamsToLogger()
Definition MRCameraOrientationPlugin.h:8