Skip to content

Commit

Permalink
Issue 5630 - CLI - need to add logging filter for stdout
Browse files Browse the repository at this point in the history
Description:  A logging filter was added for stderr, and we now need one for
stdout, otherwise we are getting duplicate output from cli tools

relates: #5630

Reviewed by: spichugi(Thanks!)
  • Loading branch information
mreynolds389 committed Feb 14, 2023
1 parent 4caf70c commit 901316e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 0 additions & 5 deletions dirsrvtests/tests/suites/export/export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---


import os
import pytest
import subprocess

from lib389.topologies import topology_st as topo
from lib389._constants import DEFAULT_SUFFIX, DEFAULT_BENAME
from lib389.utils import *
Expand Down Expand Up @@ -106,9 +104,6 @@ def test_db2ldif_cli_with_non_accessible_ldif_file_path(topo):
if format(e.returncode) == '139':
log.error('db2ldif had a Segmentation fault (core dumped)')
assert False
else:
log.info('db2ldif failed properly: error ({})'.format(e.returncode))
assert "The LDIF file location does not exist" in str(e.output)

log.info("Restarting the instance...")
topo.standalone.start()
Expand Down
6 changes: 6 additions & 0 deletions src/lib389/lib389/cli_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ def filter(self, rec):
return rec.levelno in (logging.ERROR,)


class StdOutFilter(logging.Filter):
def filter(self, rec):
return rec.levelno not in (logging.ERROR,)


def setup_script_logger(name, verbose=False):
"""Reset the python logging system for STDOUT, and attach a new
console logger with cli expected formatting.
Expand All @@ -434,6 +439,7 @@ def setup_script_logger(name, verbose=False):
log_format = '%(message)s'

log_handler.setFormatter(logging.Formatter(log_format))
log_handler.addFilter(StdOutFilter())
root.addHandler(log_handler)

log_handler_err = logging.StreamHandler(sys.stderr)
Expand Down
5 changes: 4 additions & 1 deletion src/lib389/lib389/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,10 @@ def is_dn_parent(parent_dn, child_dn, ):
def normalizeDN(dn, usespace=False):
# not great, but will do until we use a newer version of python-ldap
# that has DN utilities
ary = ldap.explode_dn(dn.lower())
try:
ary = ldap.explode_dn(dn.lower())
except ldap.DECODING_ERROR:
raise ValueError(f"Unable to normalize DN '{dn}'")
joinstr = ","
if usespace:
joinstr = ", "
Expand Down

0 comments on commit 901316e

Please sign in to comment.