Link to home
Start Free TrialLog in
Avatar of forums_mp
forums_mp

asked on

logMsg Wrapper

I'm looking at a vendor provided logMsg function

int logMsg
    (
    char * fmt,  /* format string for print */
    int    arg1, /* first of six required args for fmt */
    int    arg2,
    int    arg3,
    int    arg4,
    int    arg5,
    int    arg6
    )

With the description:

This routine logs a specified message via the logging task. This routine's syntax is similar to printf( ) -- a format string is followed by arguments to format. However, the logMsg( ) routine requires a fixed number of arguments (6).

The first drawback is it requires 6 arguments after the format string -- even if the arguments aren't used.  This makes the function slightly annoying to use. To make it appear more printf-like, I suspect I could define seven macros which will take the form: logMsgN(fmt, arg1, arg2, ..., argn) where N indicates how many of the six trailing arguments there are.

Secondly, I'd like to wrap this logMsg function in a class.  An instance of that class will get created and I could do things like:

log << MSG::ERROR << "Unable to create address for  /dd" << '\n';
log << MSG::DEBUG << "Finalizing" << '\n';
log << MSG::WARNING
      << "whatever"
           << 5
      << '\n';

I suspect with the wrapper class I may not need the macros.  The number of arguments could be inferred via  "<<".  In any event, I'm open to ideas .. I'll increase points provide a solution exists with source code results (i.e show me source..if source doesn't warrant 60 points I'll increase accordingly)
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial