FeiMsg is used by FEI API classes to report messages. You can also use it from within an application. The command line utility fei uses it for example.
You don't create an FeiMsg object in your program. Just one such object exists in program space and its created automatically for you. Instead use the global friend function to feiMsg to reference FeiMsg member functions. The general syntax is:
feiMsg().< member function >
For example:
feiMsg().record ("Hello, world!", FEI_OK);
uses the record member function to record the message Hello, world!. (The second argument is the status, or serverity, value associated with the message.)
There is a good reason for using a single object for message reporting and that's because Fei is multi-threaded. With different threads - an your application portion of a program is one thread - it's likely that more than one of them will be writting a message at the same time. The FeiMsg class controlls the activity by only allowing the existance of a single object and by serializing message reporting within that object.
By default FeiMsg writes to stderr. It can also be configured to write a log file or to send email. You open and close a log file with the member functions openLog and closeLog. To have messages mailed, setMaiTo is used. Once configured with any or all of these options, there reporting state can be turned on or off with the member functions: setPrintMessage (stderr), setLogMessge (log file) and setMailMessage (email). These functions take a boolean argument {true, false} that sets the state.
The member function record is used to report a message. The message is sent each of the report facilities (stderr, log file, email) that's configured and has a state value of true.
record takes two arguments: a formatted message and an FEI status value. FEI status values are used by all FEI classes. The values and their general meaning are:
if (status) // take action if the status is takeAction (status); // other than FEI_OK or 0.
When reporting messages you can turn on FeiMsg's header line if you like with the member function useHeader. (By default, it's turned off.) With the header turned on, each message send starts with a line that includes string value equivalent for the status value and the current system time. Use this method if you want to time stamp you messages.
FeiMsg does not return error messages; it's simply a reporting device to be used in multi-thread environments. You can get error messages directly from Fei objects using their member functions getErrno() and getMsg(). If you want to handle reporting messages yourself, turn off all of FeiMsg's reporting states, retrieve messages when you recieve an FEI status other than FEI_OK, and report them using your own mechanism.
For more information on the class, see the header file: FeiMsg.h
feiMsg().record ("Hello, world!", FEI_INFO); feiMsg().openLog ("myLogFile.log"); feiMsg().setMailMessage (true);
The logging state is set to true when the log file is opened. See setLogMessage, isLogMessage for further information.
The second and third arguments are optional and only appear if a message header is included with the message, see useHeader. The second argument is an error number to be associated with the message. This is only included if the error number is not 0. The number appears within parentheses following any severity value and preceding the date and time value in the header string. The third argument is the message serverity. Valid values are: FEI_OK, FEI_INFO, FEI_WARN, FEI_ERROR, FEI_FATAL. See the class
See also isLogMessage, setPrintMessage, setMailMessage.
See also isMailMessage, setPrintMessage, setLogMessage.
setMailTo ("jake@hardknocks.edu", "Re: file type - image");
The mail state is set to true by this memeber function. Change it with setMailMessage. Returns an FEI status value.
See also setMailMessage, isMailMessage.
See also isPrintMessage, setLogMessage, setMailMessage.
feiMsg().record ("Hellow, world!", FEI_INFO);
results in a two line message that looks like this:
Information on 4/1/1997 at 09:11:28 Hello, world!
Returns the current header state. See also isHeader.