From bde36e3cd4040cae9b9c11e6c046ceb20eaf3abe Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 26 Mar 2023 13:17:02 +0200 Subject: [PATCH] Bugfix for logging ldap debug messages with non stream logfile --- cps/services/simpleldap.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cps/services/simpleldap.py b/cps/services/simpleldap.py index 40c117b0..dc915ceb 100644 --- a/cps/services/simpleldap.py +++ b/cps/services/simpleldap.py @@ -30,6 +30,14 @@ except ImportError: log = logger.create() +class LDAPLogger(object): + + def write(self, message): + try: + log.debug(message.strip("\n").replace("\n", "")) + except Exception: + log.debug("Logging Error") + class mySimpleLDap(LDAP): @@ -38,7 +46,6 @@ class mySimpleLDap(LDAP): super(mySimpleLDap, mySimpleLDap).init_app(app) app.config.setdefault('LDAP_LOGLEVEL', 0) - @property def initialize(self): """Initialize a connection to the LDAP server. @@ -50,7 +57,7 @@ class mySimpleLDap(LDAP): conn = pyLDAP.initialize('{0}://{1}:{2}'.format( current_app.config['LDAP_SCHEMA'], current_app.config['LDAP_HOST'], - current_app.config['LDAP_PORT']), trace_level=log_level) + current_app.config['LDAP_PORT']), trace_level=log_level, trace_file=LDAPLogger()) conn.set_option(pyLDAP.OPT_NETWORK_TIMEOUT, current_app.config['LDAP_TIMEOUT']) conn = self._set_custom_options(conn)