PLCnext API Documentation 23.6.0.37
LogStream.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Commons/Diagnostics/Logging/LogLevel.hpp"
9#include <sstream>
10
11namespace Arp { namespace System { namespace Commons { namespace Diagnostics { namespace Logging { namespace Internal
12{
13// forwards
14class LogAdapter;
15}}}}}} // end of namesapce Arp::System::Commons::Diagnostics::Logging::Internal
16
17namespace Arp { namespace System { namespace Commons { namespace Diagnostics { namespace Logging
18{
19
20using LogAdapter = Internal::LogAdapter;
21
23{
24public: // construction/destruction/assignment
25 LogStream(LogLevel logLevel, std::stringstream& buffer, LogAdapter* pLogAdapter);
26 LogStream(const LogStream& arg);
27 LogStream(LogStream&& arg)noexcept;
28 ~LogStream(void);
29 LogStream& operator=(const LogStream&) = delete;
30
31public: // static fields
32 static LogStream Null;
33
34public: // overloaded operators
35 template<class T>
36 LogStream& operator<<(const T&);
37
38private: // operations
39 void Flush(void);
40
41private: // fields
42 LogLevel logLevel;
43 std::stringstream& messageBuffer;
44 LogAdapter* pLogAdapter;
45};
46
48// inline methods of class LogStream
49inline LogStream::LogStream(LogLevel logLevelArg, std::stringstream& buffer, LogAdapter* pLogAdapterArg)
50 : logLevel(logLevelArg)
51 , messageBuffer(buffer)
52 , pLogAdapter(pLogAdapterArg)
53{
54}
55
56inline LogStream::LogStream(const LogStream& arg)
57 : logLevel(arg.logLevel)
58 , messageBuffer(arg.messageBuffer)
59 , pLogAdapter(arg.pLogAdapter)
60{
61}
62
63inline LogStream::LogStream(LogStream&& arg)noexcept
64 : logLevel(arg.logLevel)
65 , messageBuffer(arg.messageBuffer)
66 , pLogAdapter(arg.pLogAdapter)
67{
68}
69
70inline LogStream::~LogStream()
71{
72 this->Flush();
73}
74
75template<class T>
76inline LogStream& LogStream::operator<<(const T& value)
77{
78 messageBuffer << value;
79 return *this;
80}
81
82}}}}} // end of namesapce Arp::System::Commons::Diagnostics::Logging
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API