LdapServer : Add custom logger support
This commit is contained in:
parent
764d92a40c
commit
93d2133376
1 changed files with 9 additions and 5 deletions
|
@ -13,19 +13,23 @@ class LdapServer(object):
|
|||
|
||||
con = 0
|
||||
|
||||
def __init__(self,uri,dn=None,pwd=None,v2=None,raiseOnError=False):
|
||||
def __init__(self,uri,dn=None,pwd=None,v2=None,raiseOnError=False, logger=False):
|
||||
self.uri = uri
|
||||
self.dn = dn
|
||||
self.pwd = pwd
|
||||
self.raiseOnError = raiseOnError
|
||||
if v2:
|
||||
self.v2=True
|
||||
if logger:
|
||||
self.logger = logger
|
||||
else:
|
||||
self.logger = logging.getLogger()
|
||||
|
||||
def _error(self,error,level=logging.WARNING):
|
||||
if self.raiseOnError:
|
||||
raise LdapServerException(error)
|
||||
else:
|
||||
logging.log(level,error)
|
||||
self.logger.log(level,error)
|
||||
|
||||
def connect(self):
|
||||
if self.con == 0:
|
||||
|
@ -63,7 +67,7 @@ class LdapServer(object):
|
|||
def add_object(self,dn,attrs):
|
||||
ldif = modlist.addModlist(attrs)
|
||||
try:
|
||||
logging.debug("LdapServer - Add %s" % dn)
|
||||
self.logger.debug("LdapServer - Add %s" % dn)
|
||||
self.con.add_s(dn,ldif)
|
||||
return True
|
||||
except ldap.LDAPError, e:
|
||||
|
@ -84,7 +88,7 @@ class LdapServer(object):
|
|||
|
||||
def rename_object(self,dn,new_rdn):
|
||||
try:
|
||||
logging.debug("LdapServer - Rename %s in %s" % (dn,new_rdn))
|
||||
self.logger.debug("LdapServer - Rename %s in %s" % (dn,new_rdn))
|
||||
self.con.rename_s(dn,new_rdn)
|
||||
return True
|
||||
except ldap.LDAPError, e:
|
||||
|
@ -94,7 +98,7 @@ class LdapServer(object):
|
|||
|
||||
def drop_object(self,dn):
|
||||
try:
|
||||
logging.debug("LdapServer - Delete %s" % dn)
|
||||
self.logger.debug("LdapServer - Delete %s" % dn)
|
||||
self.con.delete_s(dn)
|
||||
return True
|
||||
except ldap.LDAPError, e:
|
||||
|
|
Loading…
Reference in a new issue