[Ns-developers] [ns3] logging
Gustavo Carneiro
gjcarneiro at gmail.com
Thu Apr 10 10:30:29 PDT 2008
I am away from my computer and can't test now, but IIRC NS_LOG_PARAMS was
supposed to be used like this:
void foo (int xpto, char *zbr)
{
NS_LOG_PARAMS (xpto << zbr);
}
The log message would look something like:
void foo (int, char*) (xpto=123, zbr="something")
This macro avoids some tedious typing, like:
NS_LOG_DEBUG (__PRETTY_FUNCTION__<<"xpto="<<xpto << "zbr="<<zbr);
I don't remember the reason why NS_LOG_PARAMS_BEGIN, NS_LOG_PARAM,
NS_LOG_PARAMS_END exist. Maybe they are only support code for the
NS_LOG_PARAMS macro, but it was a long time ago. If those are not really
needed I guess they can be removed.
I am very fond of NS_LOG_PARAMS, though. I think your idea of optionally
filtering out the function name sounds good, as long as we don't remove the
macro as a whole; that would be a shame.
On 10/04/2008, Mathieu Lacage <mathieu.lacage at sophia.inria.fr> wrote:
>
>
> On Wed, 2008-04-09 at 17:16 -0700, Mathieu Lacage wrote:
> > hi,
> >
> > Today is not the first time I try to use unsuccessfully NS_LOG_PARAMS: I
> > just seem unable to figure out what its input is expected to be (the
> > fact that it is undocumented speaks volume) so, I looked at the code
> > today and I am even more confused by what its behavior is supposed to
> > be.
> >
> > I personally would have expected something like this:
> >
> > NS_LOG_PARAMS ("name0" << value0 << "name1" << value1 ...);
> >
> > to print something like this:
> >
> > Component:FunctionName (name0=value0, name1=value1)
>
>
> Actually, to be really specific, what I expected is that we would have a
> macro named NS_LOG_FUNCTION used like this:
>
> NS_LOG_FUNCTION ("name0"<<value0<<name1<<value1);
>
> or, if you don't care about the args,
>
> NS_LOG_FUNCTION ();
>
> which would be able to understand the log bits FUNCTION and PARAMS and
> would generate only the function name if ((flags & (FUNCTION | PARAMS))
> == FUNCTION) and both the function name and parameters if flags &
> PARAMS. I suspect very strongly that this is close to what craig
> originally proposed and implemented with the log levels having an
> ordering relationship. Although they don't have this ordering
> relationship anymore, we could trivially make NS_LOG_FUNCTION do the
> above and get the same feature set.
>
> The above would allow you to avoid duplicating the NS_LOG_FUNCTION +
> NS_LOG_PARAMS macro calls which are used everywhere in tandem to leave
> just one NS_LOG_FUNCTION.
>
> result:
> functionality: no loss
> lines of code: great decrease
>
> If this is felt the way to go, I have a small perl script to do the
> conversion.
>
>
> Mathieu
>
>
--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
More information about the Ns-developers
mailing list