idea request: generic function logging

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noah Roberts

    #1

    idea request: generic function logging

    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.

  • JoShCrUz

    #2
    Re: idea request: generic function logging

    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

    Comment

    Working...