Skip to content

Commit

Permalink
Fixed OVC logger. (openvinotoolkit#27837)
Browse files Browse the repository at this point in the history
### Details:
 - Fix OVC to not override logger if `verbose` is turned on.

### Tickets:
 - CVS-152753
  • Loading branch information
popovaan authored Dec 2, 2024
1 parent 4a4bfed commit ca670b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion tools/ovc/openvino/tools/ovc/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def convert_model(
list of paths, objects derived from BaseExtension class or lists of
objects.
:param verbose:
Print detailed information about conversion.
Print detailed information about conversion. The detailed information is logged via standard logging library.
The log level can be changed by setting the log level using logging library.
Example:
import logging
logging.getLogger().setLevel(logging.DEBUG)
:param share_weights:
Reuse weights allocated in the original model. If input model is in file,
then mmap is used to allocate weights directly from file. If input model is
Expand Down
8 changes: 5 additions & 3 deletions tools/ovc/openvino/tools/ovc/convert_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ def check_model_object(argv):


def driver(argv: argparse.Namespace, non_default_params: dict):
init_logger('ERROR', argv.verbose)

# Log dictionary with non-default cli parameters where complex classes are excluded.
log.debug(str(non_default_params))

Expand Down Expand Up @@ -433,7 +431,11 @@ def _convert(cli_parser: argparse.ArgumentParser, args, python_api_used):
telemetry.send_event('ovc', 'version', simplified_ie_version)
# Initialize logger with 'ERROR' as default level to be able to form nice messages
# before arg parser deliver log_level requested by user
init_logger('ERROR', False)
verbose = False
if "verbose" in args and args["verbose"] or "--verbose" in sys.argv:
verbose = True

init_logger('ERROR', verbose, python_api_used)
argv = None
# Minimize modifications among other places in case if multiple pieces are passed as input_model
if python_api_used:
Expand Down
2 changes: 2 additions & 0 deletions tools/ovc/openvino/tools/ovc/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ def get_convert_model_help_specifics():
{'action': 'version',
# FIXME: Why the following is not accessible from arg parser?
'version': 'OpenVINO Model Converter (ovc) {}'.format(VersionChecker().get_ie_version())},
'verbose':
{'description': 'Print detailed information about conversion.'}
}
5 changes: 4 additions & 1 deletion tools/ovc/openvino/tools/ovc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def filter(self, record: log.LogRecord):
return True # if regex wasn't set print all logs


def init_logger(lvl: str, verbose: bool):
def init_logger(lvl: str, verbose: bool, python_api_used: bool):
if verbose and python_api_used:
# We need to not override logger in case of verbose=True to allow user set a log level
return
global handler_num
log_exp = os.environ.get('MO_LOG_PATTERN')
if not verbose:
Expand Down

0 comments on commit ca670b8

Please sign in to comment.