[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: LDAP Debug messages & severity levels



Replying to old mail...

Pierangelo Masarati writes:
> Hallvard,
>
> did you get any far with your logging redesign?

It stalled on something or other I was waiting for, but here is what I
was thinking of.  Somewhat at odds with what you have committed, I don't
know whether to blend the two or stick to one of them:

ldap_log.h:

  /* Helper macro for unconditional logging - Fatal, Error, Warn. */
  #define LDAP_LOGU( level, args ) do { \
	do { \
		lutil_debug( ldap_debug, -1, args ); \
		syslog( LDAP_LEVEL_MASK((severity)), args ); \
	} while ( 0 )

  /* Helper macro for conditional logging - Info, Error. */
  #define LDAP_LOGC( level, logmask, args ) do { \
	do { \
		if ( ldap_debug & (logmask) ) \
			lutil_debug( ldap_debug, (logmask), args ); \
		if ( ldap_syslog & (level) ) \
			syslog( LDAP_LEVEL_MASK((severity)), args ); \
	} while ( 0 )

  /* Used to send several arguments to one LDAP_LOG[UC] argument */
  #define LDAP_ARG ,

  /* Logging API */

  /* Conditional logging, and only compiled in when configured */
  #define Debug Debug3
  #ifdef LDAP_DEBUG /* or should that test LDAP_DEBUG || LDAP_SYSLOG? */
  #define Debug0( logmask, fmt ) \
	LDAP_LOGC( LDAP_LEVEL_DEBUG, logmask, (fmt) )
  #define Debug1( dummy, fmt, arg1 ) ...
  #define Debug2( dummy, fmt, arg1, arg2 ) ...
  #define Debug3( dummy, fmt, arg1, arg2, arg3 ) \
	LDAP_LOGU( LDAP_LEVEL_DEBUG, logmask, \
	(fmt) LDAP_ARG(arg1) LDAP_ARG(arg2) LDAP_ARG(arg3) )
  ...
  #else
  #define Debug0( logmask, fmt ) ((void) 0)
  ...
  #endif

  /* Conditional logging, always compiled in - because Statslog()
   * will be like Info() and will always be compiled in. */
  #define Info Info3
  #define Info0( logmask, fmt ) \
	LDAP_LOGC( LDAP_LEVEL_INFO, logmask, (fmt) )
  ...

  /* Unconditional logging.
  /* The dummy argument is unused and can be removed later, but
   * is included for now so we can rename Fatal<->...<->Debug at
   * need without having to add/remove the logmask argument. */
  #define Warn Warn3
  #define Warn0( dummy, fmt )  LDAP_LOGU( LDAP_LEVEL_WARNING, (fmt) )
  ...
  #define Error Error3
  #define Error0( dummy, fmt ) LDAP_LOGU( LDAP_LEVEL_ERR, (fmt) )
  ...
  #define Fatal Fatal3
  #define Fatal0( dummy, fmt ) LDAP_LOGU( LDAP_LEVEL_CRIT, (fmt) )
  ...

I've taken the opportunity to rename loglevel to logmask, which more
accurately describes what it is.

-- 
Hallvard