messageStream Class Reference

Handle output messages in a simple, consistent stream-based manner. More...

Inheritance diagram for messageStream:
Collaboration diagram for messageStream:

Public Types

enum  errorSeverity : int {
  INFO = 1, WARNING, SERIOUS, FATAL,
  USE_STDERR = 0x80
}
 Message type, error severity flags. More...
 

Public Member Functions

 messageStream (errorSeverity severity, int maxErrors=0, bool use_stderr=false)
 Construct untitled with given characteristics. More...
 
 messageStream (const char *title, errorSeverity severity, int maxErrors=0, bool use_stderr=false)
 Construct from components. More...
 
 messageStream (string title, errorSeverity severity, int maxErrors=0, bool use_stderr=false)
 Construct from components. More...
 
 messageStream (const dictionary &dict)
 Construct from dictionary as Fatal, extracting 'title'. More...
 
const stringtitle () const noexcept
 The title of this error type. More...
 
int maxErrors () const noexcept
 The maximum number of errors before program termination. More...
 
int maxErrors (int nErrors) noexcept
 Set the maximum number of errors before program termination. More...
 
OSstreamstream (OSstream *alternative=nullptr, int communicator=-1)
 Return OSstream for output operations. More...
 
OSstreammasterStream (int communicator)
 Return OSstream for output operations on the master process only, Snull on other processes. More...
 
std::ostream & stdStream ()
 Return std::ostream for output operations. More...
 
OSstreamdeprecated (const int afterVersion, const char *functionName=nullptr, const char *sourceFileName=nullptr, const int sourceFileLineNumber=0)
 Report deprecation (after specified API version) with 'From function-name, source file, line number'. More...
 
 operator OSstream & ()
 Implicit cast to OSstream for << operations. More...
 
OSstreamoperator() ()
 Explicitly convert to OSstream for << operations. More...
 
OSstreamoperator() (const std::string &functionName, const char *sourceFileName=nullptr, const int sourceFileLineNumber=0)
 Report 'From function-name', optionally with 'source file, line number'. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName=nullptr, const int sourceFileLineNumber=0)
 Report 'From function-name', optionally with 'source file, line number'. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const std::string &ioFileName, const label ioStartLineNumber=-1, const label ioEndLineNumber=-1)
 Report 'From function-name, source file, line number' as well as io-file name and location. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const IOstream &)
 Report 'From function-name, source file, line number' as well as io-file name and location. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const dictionary &)
 Report 'From function-name, source file, line number' as well as io-file name and location. More...
 

Static Public Attributes

static int level
 The output level (verbosity) of messages. More...
 
static int redirect
 The output redirection of messages. More...
 

Protected Attributes

string title_
 The title of this error type. More...
 
int severity_
 The message type / error severity, possibly with USE_STDERR mask. More...
 
int maxErrors_
 The maximum number of errors before program termination. More...
 
int errorCount_
 The current number of errors counted. More...
 

Detailed Description

Handle output messages in a simple, consistent stream-based manner.

The messageStream class is globally instantiated with a title string and a severity (which controls the program termination), optionally with a max number of errors before termination.

Errors, messages and other data are sent to the messageStream class in the standard manner.

For parallel applications, the output for 'standard' messages (Info, Warnings) is effectively suppressed on all sub-processes, which results in a single output message instead of a flood of output messages from each process. The error type of messages do, however, retain output on all processes, which ensures that parallel termination occurs correctly and the source of the problem is properly traceable to the originating processor.

Source files

Definition at line 70 of file messageStream.H.

Member Enumeration Documentation

◆ errorSeverity

enum errorSeverity : int

Message type, error severity flags.

Enumerator
INFO 

General information output (stdout)

WARNING 

Warning of possible problem.

SERIOUS 

A serious problem - eg, data corruption.

FATAL 

A fatal error.

USE_STDERR 

Bitmask for stderr output (for the above enums)

Definition at line 77 of file messageStream.H.

Constructor & Destructor Documentation

◆ messageStream() [1/4]

messageStream ( errorSeverity  severity,
int  maxErrors = 0,
bool  use_stderr = false 
)
explicit

Construct untitled with given characteristics.

Definition at line 44 of file messageStream.C.

◆ messageStream() [2/4]

messageStream ( const char *  title,
errorSeverity  severity,
int  maxErrors = 0,
bool  use_stderr = false 
)

Construct from components.

Definition at line 62 of file messageStream.C.

◆ messageStream() [3/4]

messageStream ( string  title,
errorSeverity  severity,
int  maxErrors = 0,
bool  use_stderr = false 
)

Construct from components.

Definition at line 79 of file messageStream.C.

◆ messageStream() [4/4]

messageStream ( const dictionary dict)
explicit

Construct from dictionary as Fatal, extracting 'title'.

Definition at line 92 of file messageStream.C.

Member Function Documentation

◆ title()

const string& title ( ) const
inlinenoexcept

The title of this error type.

Definition at line 188 of file messageStream.H.

References messageStream::title_.

◆ maxErrors() [1/2]

int maxErrors ( ) const
inlinenoexcept

The maximum number of errors before program termination.

Definition at line 196 of file messageStream.H.

References messageStream::maxErrors_.

◆ maxErrors() [2/2]

int maxErrors ( int  nErrors)
inlinenoexcept

Set the maximum number of errors before program termination.

Returns
the previous value for maxErrors

Definition at line 206 of file messageStream.H.

References messageStream::maxErrors_.

◆ stream()

Foam::OSstream & stream ( OSstream alternative = nullptr,
int  communicator = -1 
)

Return OSstream for output operations.

Parameters
alternativeAn alternative output stream (serial-only)
communicatorCommunicator. Negative is treated like UPstream::worldComm

Definition at line 101 of file messageStream.C.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, Foam::infoDetailLevel, UPstream::master(), UPstream::parRun(), Foam::Perr, Foam::Pout, Foam::Serr, Foam::Snull, Foam::Sout, and UPstream::worldComm.

Referenced by objectRegistry::checkCacheTemporaryObjects(), snappySnapDriver::doSnap(), messageStream::operator OSstream &(), messageStream::operator()(), GAMGAgglomeration::printLevels(), ParRunControl::runPar(), and ParRunControl::~ParRunControl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ masterStream()

Foam::OSstream & masterStream ( int  communicator)

Return OSstream for output operations on the master process only, Snull on other processes.

A negative communicator is treated like UPstream::worldComm

Definition at line 181 of file messageStream.C.

References Foam::endl(), UPstream::master(), Foam::Perr, error::printStack(), Foam::Snull, UPstream::warnComm, and UPstream::worldComm.

Referenced by viewFactor::calculate(), AMIInterpolation::normaliseWeights(), smoothSolver::solve(), fvMatrix< Type >::fvSolver::solve(), GAMGSolver::solve(), fvMatrix< Type >::solveCoupled(), fvMatrix< Type >::solver(), fvMatrix< Type >::solveSegregated(), and fvMatrix< Type >::solveSegregatedOrCoupled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stdStream()

std::ostream & stdStream ( )

Return std::ostream for output operations.

Definition at line 203 of file messageStream.C.

Referenced by argList::argList(), argList::parse(), Foam::printTimingDetail(), and argList::printUsage().

Here is the caller graph for this function:

◆ deprecated()

Foam::OSstream & deprecated ( const int  afterVersion,
const char *  functionName = nullptr,
const char *  sourceFileName = nullptr,
const int  sourceFileLineNumber = 0 
)

Report deprecation (after specified API version) with 'From function-name, source file, line number'.

Returns
OSstream for further operations

Definition at line 213 of file messageStream.C.

References Foam::foamVersion::api, Foam::nl, and os().

Here is the call graph for this function:

◆ operator OSstream &()

operator OSstream & ( )
inline

Implicit cast to OSstream for << operations.

Definition at line 258 of file messageStream.H.

References messageStream::stream().

Here is the call graph for this function:

◆ operator()() [1/6]

OSstream& operator() ( )
inline

Explicitly convert to OSstream for << operations.

Definition at line 266 of file messageStream.H.

References messageStream::stream().

Here is the call graph for this function:

◆ operator()() [2/6]

Foam::OSstream & operator() ( const std::string &  functionName,
const char *  sourceFileName = nullptr,
const int  sourceFileLineNumber = 0 
)

Report 'From function-name', optionally with 'source file, line number'.

Returns
OSstream for further operations

Definition at line 274 of file messageStream.C.

References Foam::nl, and os().

Here is the call graph for this function:

◆ operator()() [3/6]

Foam::OSstream & operator() ( const char *  functionName,
const char *  sourceFileName = nullptr,
const int  sourceFileLineNumber = 0 
)

Report 'From function-name', optionally with 'source file, line number'.

Returns
OSstream for further operations

Definition at line 304 of file messageStream.C.

References Foam::nl, and os().

Here is the call graph for this function:

◆ operator()() [4/6]

Foam::OSstream & operator() ( const char *  functionName,
const char *  sourceFileName,
const int  sourceFileLineNumber,
const std::string &  ioFileName,
const label  ioStartLineNumber = -1,
const label  ioEndLineNumber = -1 
)

Report 'From function-name, source file, line number' as well as io-file name and location.

Returns
OSstream for further operations

Definition at line 334 of file messageStream.C.

References Foam::endl(), and os().

Here is the call graph for this function:

◆ operator()() [5/6]

Foam::OSstream & operator() ( const char *  functionName,
const char *  sourceFileName,
const int  sourceFileLineNumber,
const IOstream ioStream 
)

Report 'From function-name, source file, line number' as well as io-file name and location.

Returns
OSstream for further operations
Parameters
ioStreamProvides name and lineNumber

Definition at line 369 of file messageStream.C.

◆ operator()() [6/6]

Foam::OSstream & operator() ( const char *  functionName,
const char *  sourceFileName,
const int  sourceFileLineNumber,
const dictionary dict 
)

Report 'From function-name, source file, line number' as well as io-file name and location.

Returns
OSstream for further operations
Parameters
dictProvides name, startLine, endLine

Definition at line 389 of file messageStream.C.

References dict, dictionary::endLineNumber(), dictionary::relativeName(), and dictionary::startLineNumber().

Here is the call graph for this function:

Member Data Documentation

◆ title_

string title_
protected

The title of this error type.

Definition at line 99 of file messageStream.H.

Referenced by messageStream::title().

◆ severity_

int severity_
protected

The message type / error severity, possibly with USE_STDERR mask.

Definition at line 104 of file messageStream.H.

◆ maxErrors_

int maxErrors_
protected

The maximum number of errors before program termination.

Definition at line 109 of file messageStream.H.

Referenced by messageStream::maxErrors().

◆ errorCount_

int errorCount_
protected

The current number of errors counted.

Definition at line 114 of file messageStream.H.

◆ level

int level
static

The output level (verbosity) of messages.

  • level == 0 : suppress all output
  • level == 1 : normal output
  • level >= 2 : report source file name and line number if available
Note
The default level is normally 2.

Definition at line 131 of file messageStream.H.

Referenced by IOobject::setBad(), error::write(), and IOerror::write().

◆ redirect

int redirect
static

The output redirection of messages.

  • redirect == 2 : use stderr instead of stdout

Definition at line 139 of file messageStream.H.


The documentation for this class was generated from the following files: