messageStream Class Reference

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

Inheritance diagram for messageStream:
[legend]
Collaboration diagram for messageStream:
[legend]

Public Types

enum  errorSeverity {
  INFO = 1 , INFO_STDERR , WARNING , SERIOUS ,
  FATAL
}
 Message type, error severity flags. More...
 

Public Member Functions

 messageStream (const string &title, const errorSeverity severity, const int maxErrors=0)
 Construct from components. More...
 
 messageStream (const dictionary &dict)
 Construct as Fatal from dictionary, extracting the '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)
 
OSstreammasterStream (const label communicator)
 
std::ostream & stdStream ()
 Return std::ostream for output operations. More...
 
 operator OSstream & ()
 Implicit cast to OSstream for << operations. More...
 
OSstreamoperator() ()
 Explicitly convert to OSstream for << operations. More...
 
OSstreamoperator() (const string &functionName)
 Report 'From function-name'. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 
OSstreamoperator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 Report 'From function-name, source file, line number'. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const string &ioFileName, const label ioStartLineNumber=-1, const label ioEndLineNumber=-1)
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const IOstream &)
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const dictionary &)
 

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_
 
errorSeverity severity_
 
int maxErrors_
 
int errorCount_
 

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 73 of file messageStream.H.

Member Enumeration Documentation

◆ errorSeverity

Message type, error severity flags.

Enumerator
INFO 

General information output (stdout)

INFO_STDERR 

General information output (stderr)

WARNING 

Warning of possible problem.

SERIOUS 

A serious problem - eg, data corruption.

FATAL 

A fatal error.

Definition at line 78 of file messageStream.H.

Constructor & Destructor Documentation

◆ messageStream() [1/2]

messageStream ( const string title,
const errorSeverity  severity,
const int  maxErrors = 0 
)

Construct from components.

Definition at line 46 of file messageStream.C.

◆ messageStream() [2/2]

messageStream ( const dictionary dict)
explicit

Construct as Fatal from dictionary, extracting the 'title'.

Definition at line 60 of file messageStream.C.

Member Function Documentation

◆ title()

const string & title ( ) const
inlinenoexcept

The title of this error type.

Definition at line 137 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 143 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 150 of file messageStream.H.

◆ stream()

Foam::OSstream & stream ( OSstream alternative = nullptr)

Return OSstream for output operations. Use the alternative stream for serial-only output if it is a valid pointer.

Definition at line 71 of file messageStream.C.

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

Referenced by GAMGAgglomeration::compactLevels(), messageStream::operator OSstream &(), and messageStream::operator()().

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

◆ masterStream()

Foam::OSstream & masterStream ( const label  communicator)

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

Definition at line 140 of file messageStream.C.

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

Referenced by viewFactor::calculate(), fvMatrix< Type >::fvSolver::solve(), GAMGSolver::solve(), smoothSolver::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 157 of file messageStream.C.

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

Here is the caller graph for this function:

◆ operator OSstream &()

operator OSstream & ( )
inline

Implicit cast to OSstream for << operations.

Definition at line 173 of file messageStream.H.

References messageStream::stream().

Here is the call graph for this function:

◆ operator()() [1/7]

OSstream & operator() ( )
inline

Explicitly convert to OSstream for << operations.

Definition at line 179 of file messageStream.H.

References messageStream::stream().

Here is the call graph for this function:

◆ operator()() [2/7]

Foam::OSstream & operator() ( const string functionName)

Report 'From function-name'.

Returns
OSstream for further operations

Definition at line 165 of file messageStream.C.

References Foam::nl, and os().

Here is the call graph for this function:

◆ operator()() [3/7]

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

Report 'From function-name, source file, line number' Print basic message

Returns
OSstream for further operations

Definition at line 182 of file messageStream.C.

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

Here is the call graph for this function:

◆ operator()() [4/7]

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

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

Returns
OSstream for further operations

Definition at line 201 of file messageStream.C.

◆ operator()() [5/7]

Foam::OSstream & operator() ( const char *  functionName,
const char *  sourceFileName,
const int  sourceFileLineNumber,
const 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 217 of file messageStream.C.

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

Here is the call graph for this function:

◆ operator()() [6/7]

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 251 of file messageStream.C.

◆ operator()() [7/7]

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 271 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

Definition at line 95 of file messageStream.H.

Referenced by messageStream::title().

◆ severity_

errorSeverity severity_
protected

Definition at line 96 of file messageStream.H.

◆ maxErrors_

int maxErrors_
protected

Definition at line 97 of file messageStream.H.

Referenced by messageStream::maxErrors().

◆ errorCount_

int errorCount_
protected

Definition at line 98 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 112 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 117 of file messageStream.H.


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