idea request: generic function logging

N

Noah Roberts

I need to create a log file that logs calls to a certain API. The
obvious way to do this is to put a bunch of output functions
before/after calls but it seems to me that there should be a generic
way to do this. Perhaps some way to override or use boost::function so
that you just wrap up your function in one of these function logging
objects and then invoke it...it does the rest. That is the kind of
thing I am looking for.

Anyone got any great ideas how to do this? The one I have involves
figuring out how function works and sort of recreating that
functionality I would need to make this work. I'm lazy enough to want
to find an easier way.
 
J

JoShCrUz

This is a very good case for using aspects :) shame C++ doesn't support
them by default ... if you could use a variant (like AspectC++ - see:
http://en.wikipedia.org/wiki/AspectC++, main link is:
http://www.aspectc.org/) you could potentially log pre-call and
post-call of all the functions you need.

As simple as creating an aspect using:

advice pointcut : before(...) {...}
the advice code is executed before the join points in the pointcut
advice pointcut : after(...) {...}
the advice code is executed after the join points in the pointcut
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top