An open source method of characteristics neutron transport code.
log.h File Reference

Utility functions for writing log messages to the screen. More...

Go to the source code of this file.

Typedefs

typedef enum logLevels logLevel
 

Enumerations

enum  logLevels {
  DEBUG, INFO, INFO_ONCE, NORMAL,
  NODAL, SEPARATOR, HEADER, TITLE,
  WARNING, WARNING_ONCE, CRITICAL, RESULT,
  UNITTEST, ERROR
}
 Logging levels characterize an ordered set of message types which may be printed to the screen. More...
 

Functions

void set_err (const char *msg)
 A function stub used to convert C++ exceptions into Python exceptions through SWIG. More...
 
void initialize_logger ()
 Initializes the logger for use. More...
 
void set_output_directory (char *directory)
 Sets the output directory for log files. More...
 
const char * get_output_directory ()
 Returns the output directory for log files. More...
 
void set_log_filename (char *filename)
 Sets the name for the log file. More...
 
const char * get_log_filename ()
 Returns the log filename. More...
 
void set_separator_character (char c)
 Sets the character to be used when printing SEPARATOR log messages. More...
 
char get_separator_character ()
 Returns the character used to format SEPARATOR log messages. More...
 
void set_header_character (char c)
 Sets the character to be used when printing HEADER log messages. More...
 
char get_header_character ()
 Returns the character used to format HEADER type log messages. More...
 
void set_title_character (char c)
 Sets the character to be used when printing TITLE log messages. More...
 
char get_title_character ()
 Returns the character used to format TITLE log messages. More...
 
void set_line_length (int length)
 Sets the maximum line length for log messages. More...
 
void set_log_level (const char *new_level)
 Sets the minimum log message level which will be printed to the console and to the log file. More...
 
void set_log_level (int new_level)
 Sets the minimum log message level which will be printed to the console and to the log file. This is an overloaded version to handle a logLevel type input. More...
 
int get_log_level ()
 Return the minimum level for log messages printed to the screen. More...
 
void log_printf (logLevel level, const char *format,...)
 Print a formatted message to the console. More...
 
std::string create_multiline_msg (std::string level, std::string message)
 Breaks up a message which is too long for a single line into a multiline message. More...
 

Detailed Description

Utility functions for writing log messages to the screen.

Applies level-based logging to print formatted messages to the screen and to a log file.

Author
William Boyd (wboyd.nosp@m.@mit.nosp@m..edu)
Date
January 22, 2012

Enumeration Type Documentation

◆ logLevels

enum logLevels

Logging levels characterize an ordered set of message types which may be printed to the screen.

Enumerator
DEBUG 

A debugging message

INFO 

An informational but verbose message

INFO_ONCE 

An informational verbose message - printed by rank 0 process only

NORMAL 

A brief progress update on run progress

NODAL 

A brief progress update by node on run progress

SEPARATOR 

A message of a single line of characters

HEADER 

A message centered within a line of characters

TITLE 

A message sandwiched between two lines of characters

WARNING 

A message to warn the user

WARNING_ONCE 

A message to warn the user - to be printed by rank 0 process only

CRITICAL 

A message to warn of critical program conditions

RESULT 

A message containing program results

UNITTEST 

A messsage for unit testing

ERROR 

A message reporting error conditions

Function Documentation

◆ create_multiline_msg()

std::string create_multiline_msg ( std::string  level,
std::string  message 
)

Breaks up a message which is too long for a single line into a multiline message.

This is an internal function which is called by log_printf and should not be called directly by the user.

Parameters
levela string containing log level prefix
messagea string containing the log message
Returns
a string with a formatted multiline message

◆ get_header_character()

char get_header_character ( )

Returns the character used to format HEADER type log messages.

Returns
the character used for HEADER log messages

◆ get_log_filename()

const char* get_log_filename ( )

Returns the log filename.

Returns
a character array for the log filename

◆ get_log_level()

int get_log_level ( )

Return the minimum level for log messages printed to the screen.

Returns
the minimum level for log messages

◆ get_output_directory()

const char* get_output_directory ( )

Returns the output directory for log files.

Returns
a character array for the log file directory

◆ get_separator_character()

char get_separator_character ( )

Returns the character used to format SEPARATOR log messages.

Returns
the character used for SEPARATOR log messages

◆ get_title_character()

char get_title_character ( )

Returns the character used to format TITLE log messages.

Returns
the character used for TITLE log messages

◆ initialize_logger()

void initialize_logger ( )

Initializes the logger for use.

This should be immediately called when the logger is imported into Python and before any of its other routines are called. The routine initializes an OpenMP mutual exclusion lock which is used to preclude race conditions from occurring when an ERROR message is reported and program execution is terminated.

◆ log_printf()

void log_printf ( logLevel  level,
const char *  format,
  ... 
)

Print a formatted message to the console.

If the logging level is ERROR, this function will throw a runtime exception

Parameters
levelthe logging level for this message
formatvariable list of C++ formatted arguments

◆ set_err()

void set_err ( const char *  msg)

A function stub used to convert C++ exceptions into Python exceptions through SWIG.

This method is not defined in the C++ source. It is defined in the SWIG inteface files (i.e., openmoc/openmoc.i)

Parameters
msga character array for the exception message

◆ set_header_character()

void set_header_character ( char  c)

Sets the character to be used when printing HEADER log messages.

Parameters
cthe character for HEADER log messages

◆ set_line_length()

void set_line_length ( int  length)

Sets the maximum line length for log messages.

Messages longer than this amount will be broken up into multiline messages.

Parameters
lengththe maximum log message line length in characters

◆ set_log_filename()

void set_log_filename ( char *  filename)

Sets the name for the log file.

Parameters
filenamea character array for log filename

◆ set_log_level() [1/2]

void set_log_level ( const char *  new_level)

Sets the minimum log message level which will be printed to the console and to the log file.

Parameters
new_levelthe minimum logging level as a character array

◆ set_log_level() [2/2]

void set_log_level ( int  new_level)

Sets the minimum log message level which will be printed to the console and to the log file. This is an overloaded version to handle a logLevel type input.

Parameters
new_levelthe minimum logging level as an int(or enum type logLevel)

◆ set_output_directory()

void set_output_directory ( char *  directory)

Sets the output directory for log files.

If the directory does not exist, it creates it for the user.

Parameters
directorya character array for the log file directory

◆ set_separator_character()

void set_separator_character ( char  c)

Sets the character to be used when printing SEPARATOR log messages.

Parameters
cthe character for SEPARATOR log messages

◆ set_title_character()

void set_title_character ( char  c)

Sets the character to be used when printing TITLE log messages.

Parameters
cthe character for TITLE log messages