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

RE: NEW_LOGGING



It appears that at least the LEVEL argument needs to be available to the
lutil_log function, so that it can pass it on via syslog(). One way to
do this would be to provide the level redundantly, once in the macro
arguments
and once in the log arguments. (blech)

As another alternative, hard-code the level in individual log functions:

#define	LDAP_LOG_WARNING(subsys, args) do { \
     if (ldap_loglevels[LDAP_SUBSYS_##subsys] >= LDAP_LEVEL_WARNING) \
	 lutil_log_warning args; \
   } while(0)

  -- Howard Chu
  Chief Architect, Symas Corp.       Director, Highland Sun
  http://www.symas.com               http://highlandsun.com/hyc
  Symas: Premier OpenSource Development and Support

> -----Original Message-----
> From: Hallvard B Furuseth [mailto:h.b.furuseth@usit.uio.no]

> 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