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
|
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.uri = uri
|
||||||
self.dn = dn
|
self.dn = dn
|
||||||
self.pwd = pwd
|
self.pwd = pwd
|
||||||
self.raiseOnError = raiseOnError
|
self.raiseOnError = raiseOnError
|
||||||
if v2:
|
if v2:
|
||||||
self.v2=True
|
self.v2=True
|
||||||
|
if logger:
|
||||||
|
self.logger = logger
|
||||||
|
else:
|
||||||
|
self.logger = logging.getLogger()
|
||||||
|
|
||||||
def _error(self,error,level=logging.WARNING):
|
def _error(self,error,level=logging.WARNING):
|
||||||
if self.raiseOnError:
|
if self.raiseOnError:
|
||||||
raise LdapServerException(error)
|
raise LdapServerException(error)
|
||||||
else:
|
else:
|
||||||
logging.log(level,error)
|
self.logger.log(level,error)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
if self.con == 0:
|
if self.con == 0:
|
||||||
|
@ -63,7 +67,7 @@ class LdapServer(object):
|
||||||
def add_object(self,dn,attrs):
|
def add_object(self,dn,attrs):
|
||||||
ldif = modlist.addModlist(attrs)
|
ldif = modlist.addModlist(attrs)
|
||||||
try:
|
try:
|
||||||
logging.debug("LdapServer - Add %s" % dn)
|
self.logger.debug("LdapServer - Add %s" % dn)
|
||||||
self.con.add_s(dn,ldif)
|
self.con.add_s(dn,ldif)
|
||||||
return True
|
return True
|
||||||
except ldap.LDAPError, e:
|
except ldap.LDAPError, e:
|
||||||
|
@ -84,7 +88,7 @@ class LdapServer(object):
|
||||||
|
|
||||||
def rename_object(self,dn,new_rdn):
|
def rename_object(self,dn,new_rdn):
|
||||||
try:
|
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)
|
self.con.rename_s(dn,new_rdn)
|
||||||
return True
|
return True
|
||||||
except ldap.LDAPError, e:
|
except ldap.LDAPError, e:
|
||||||
|
@ -94,7 +98,7 @@ class LdapServer(object):
|
||||||
|
|
||||||
def drop_object(self,dn):
|
def drop_object(self,dn):
|
||||||
try:
|
try:
|
||||||
logging.debug("LdapServer - Delete %s" % dn)
|
self.logger.debug("LdapServer - Delete %s" % dn)
|
||||||
self.con.delete_s(dn)
|
self.con.delete_s(dn)
|
||||||
return True
|
return True
|
||||||
except ldap.LDAPError, e:
|
except ldap.LDAPError, e:
|
||||||
|
|
Loading…
Reference in a new issue