[PATCH 06/35] monitor: Create a log() macro.

Martin Wilck mwilck at suse.com
Thu Feb 4 04:14:23 EST 2021


On Thu, 2021-02-04 at 08:01 +0100, Hannes Reinecke wrote:
> On 1/26/21 9:32 PM, mwilck at suse.com wrote:
> > +               int __lvl =
> > (lvl);                                      \
> > +                                                                  
> >      \
> > +               if (__lvl <= MAX_LOGLEVEL && __lvl <= log_level)
> > {      \
> > +                       if (log_timestamp)
> > {                            \
> > +                               struct timespec
> > __ts;                   \
> > +                                                                  
> >      \
> > +                               clock_gettime(CLOCK_MONOTONIC,
> > &__ts);  \
> > +                               fprintf(stderr,                    
> >      \
> > +                                       _TIME_FMT _func_fmt
> > format,     \
> > +                                       __ts.tv_sec, __ts.tv_nsec /
> > 1000,\
> > +                                       _func_arg,                 
> >      \
> > +                                       ##__VA_ARGS__);            
> >      \
> > +                       } else
> > {                                        \
> > +                               fprintf(stderr, _func_fmt
> > format,       \
> > +                                       _func_arg,                 
> >      \
> > +                                       ##__VA_ARGS__);            
> >      \
> > +                       };                                         
> >      \
> > +               }                                                  
> >      \
> > +       } while (0)
> > +
> > +#endif /* _LOG_H */
> > 
> Urgh. Long macros are always horrible.
> Can't you convert it into a function?

Sure. It won't work without macros, but I can write smaller ones.

> It might also be an idea to move this as the first function, as it's
> arguably an extension to existing functionality, and not directly 
> related to the monitor.

Ok.

Thanks,
Martin





More information about the Linux-nvme mailing list