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

Re: NEW_LOGGING



Howard Chu wrote:

> #define	LDAP_SUBSYS(x)	LDAP_SUBSYS_ ## x
> #define	LDAP_LEVEL(x)	LDAP_LEVEL_ ## x
> 
> #define	LDAP_LOG(a, b, args) \
> 	if (ldap_loglevels[LDAP_SUBSYS(a)] >= LDAP_LEVEL(b))	lutil_log args

That will expand the a and b argument if either is a macro.  To avoid
that, put it all directly in the LDAP_LOG macro.  (And of course you
need a do{}while(0) wrapper, so `if(...) LDAP_LOG(...) else' works.)

#define	LDAP_LOG(a, b, args) do { \
    if (ldap_loglevels[LDAP_SUBSYS_##a] >= LDAP_LEVEL_##b) lutil_log args; \
  } while(0)


But where is the value from the -d argument in all this?


BTW, if you are interested, here is a script which changes
   LDAP_LOG(( "foo", LDAP_LEVEL_BAR, "baz" ))
to LDAP_LOG(( foo, BAR, ( "baz" ))
except that foo is sometimes changed to a subsystem, in cases where
the choice seemed reasonably obvious.

#!/bin/sh
perl -i~ -0777pe '
  BEGIN {
    %s2o=
       ("aci"		=> "ACL",
	"acl"		=> "ACL",
	"backend"	=> "BACKEND",
	"liblber"	=> "BER",
	"cache"		=> "CACHE",
	"dbcache"	=> "CACHE",
	"config"	=> "CONFIG",
	"connection"	=> "CONNECTION",
	"filter"	=> "FILTER",
	"getfilter"	=> "FILTER",
	"index"		=> "INDEX",
	"filterindex"	=> "INDEX",  # or "FILTER"?
	"operation"	=> "OPERATION",
	"abandon"	=> "OPERATION",
	"add"		=> "OPERATION",
	"bind"		=> "OPERATION",
	"compare"	=> "OPERATION",
	"delete"	=> "OPERATION",
	"extended"	=> "OPERATION",
	"ldap_op"	=> "OPERATION",
	"modify"	=> "OPERATION",
	"modrdn"	=> "OPERATION",
	"request"	=> "OPERATION",
	"result"	=> "OPERATION",
	"search"	=> "OPERATION",
	"unbind"	=> "OPERATION");
  }
  sub fix { my($x) = @_; $x =~ tr/-/_/; $x; }
  s/(\n[ \t]*LDAP_LOG *\()\(([ \t]*)\" ?([-\w]+)\"(,\s*)LDAP_LEVEL_(\w+,\s*)/
	"$1$2" . ($s2o{$3} || fix($3)) . "$4$5($2"
  /ge;
' `find * -name '*.c' -print | xargs grep -l LDAP_LOG`

It leaves multi-line arguments remaining in double () somewhat wrongly
indented, though.

-- 
Hallvard