Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Nektar::StreamOutput Class Reference

Log output for std::ostream objects. More...

#include <Log.hpp>

Inheritance diagram for Nektar::StreamOutput:
[legend]

Public Member Functions

 StreamOutput (std::ostream &os)
 Construct a stream output from the stream os.
 
 ~StreamOutput () override=default
 Default destructor.
 
void Log (const std::string &msg) override
 Writes a log message to m_os.
 
- Public Member Functions inherited from Nektar::LogOutput
 LogOutput ()=default
 Default constructor.
 
virtual ~LogOutput ()=default
 
bool IsTty () const
 Returns true if this is an interactive (tty) terminal (e.g. stdout).
 

Private Member Functions

void Finalise () override
 Finalise routine. By default we do nothing for streams and assume this will be handled by the caller.
 

Private Attributes

std::ostream & m_os
 Reference to output stream.
 

Additional Inherited Members

- Protected Attributes inherited from Nektar::LogOutput
bool m_isTty = true
 True if this log output is tty-based.
 

Detailed Description

Log output for std::ostream objects.

Definition at line 120 of file Log.hpp.

Constructor & Destructor Documentation

◆ StreamOutput()

Nektar::StreamOutput::StreamOutput ( std::ostream &  os)
inline

Construct a stream output from the stream os.

This attempts to determine whether the os is either std::cout or std::cerr, so that it can distinguish between tty-type output or file/buffer-based output streams.

Definition at line 130 of file Log.hpp.

130 : LogOutput(), m_os(os)
131 {
132 // Bit of a hack to figure out if we are a tty.
133 if ((&os == &std::cout && !ISSTDOUTTTY) ||
134 (&os == &std::cerr && !ISSTDERRTTY))
135 {
136 m_isTty = false;
137 }
138 }
#define ISSTDERRTTY
Definition Log.hpp:54
#define ISSTDOUTTTY
Definition Log.hpp:53
LogOutput()=default
Default constructor.
bool m_isTty
True if this log output is tty-based.
Definition Log.hpp:106
std::ostream & m_os
Reference to output stream.
Definition Log.hpp:153

References ISSTDERRTTY, ISSTDOUTTTY, and Nektar::LogOutput::m_isTty.

◆ ~StreamOutput()

Nektar::StreamOutput::~StreamOutput ( )
overridedefault

Default destructor.

Member Function Documentation

◆ Finalise()

void Nektar::StreamOutput::Finalise ( )
inlineoverrideprivatevirtual

Finalise routine. By default we do nothing for streams and assume this will be handled by the caller.

Implements Nektar::LogOutput.

Definition at line 157 of file Log.hpp.

158 {
159 }

◆ Log()

void Nektar::StreamOutput::Log ( const std::string &  msg)
inlineoverridevirtual

Writes a log message to m_os.

Implements Nektar::LogOutput.

Definition at line 146 of file Log.hpp.

147 {
148 m_os << msg << std::flush;
149 }

References m_os.

Member Data Documentation

◆ m_os

std::ostream& Nektar::StreamOutput::m_os
private

Reference to output stream.

Definition at line 153 of file Log.hpp.

Referenced by Log().