PLCnext API Documentation  22.9.0.33
LogStream.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Diagnostics/Logging/LogLevel.hpp"
9 #include <sstream>
10 
11 namespace Arp { namespace System { namespace Commons { namespace Diagnostics { namespace Logging { namespace Internal
12 {
13 // forwards
14 class LogAdapter;
15 }}}}}} // end of namesapce Arp::System::Commons::Diagnostics::Logging::Internal
16 
17 namespace Arp { namespace System { namespace Commons { namespace Diagnostics { namespace Logging
18 {
19 
20 using LogAdapter = Internal::LogAdapter;
21 
22 class LogStream
23 {
24 public: // 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 
31 public: // static fields
32  static LogStream Null;
33 
34 public: // overloaded operators
35  template<class T>
36  LogStream& operator<<(const T&);
37 
38 private: // operations
39  void Flush(void);
40 
41 private: // fields
42  LogLevel logLevel;
43  std::stringstream& messageBuffer;
44  LogAdapter* pLogAdapter;
45 };
46 
48 // inline methods of class LogStream
49 inline LogStream::LogStream(LogLevel logLevelArg, std::stringstream& buffer, LogAdapter* pLogAdapterArg)
50  : logLevel(logLevelArg)
51  , messageBuffer(buffer)
52  , pLogAdapter(pLogAdapterArg)
53 {
54 }
55 
56 inline LogStream::LogStream(const LogStream& arg)
57  : logLevel(arg.logLevel)
58  , messageBuffer(arg.messageBuffer)
59  , pLogAdapter(arg.pLogAdapter)
60 {
61 }
62 
63 inline LogStream::LogStream(LogStream&& arg)noexcept
64  : logLevel(arg.logLevel)
65  , messageBuffer(arg.messageBuffer)
66  , pLogAdapter(arg.pLogAdapter)
67 {
68 }
69 
70 inline LogStream::~LogStream()
71 {
72  this->Flush();
73 }
74 
75 template<class T>
76 inline 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