Files
openvino/tests/layer_tests/common/logger.py
T
0b708b5eff updated py_checks.yml , workflow to be triggered (#17956)
* updated py_checks , trying to trigger workflow

* trail trigger

* undone changes

* changes after PR

* corrected flake for logger , constants .py

* fixed flake8 test on modified files

* fixed flake8 test on modified files

* fixed logger.py to trigger workflow

* Update .github/workflows/py_checks.yml

Co-authored-by: Przemyslaw Wysocki <przemyslaw.wysocki@intel.com>

* Update .github/workflows/py_checks.yml

Co-authored-by: Anastasia Kuporosova <anastasia.kuporosova@intel.com>

---------

Co-authored-by: Przemyslaw Wysocki <przemyslaw.wysocki@intel.com>
Co-authored-by: Anastasia Kuporosova <anastasia.kuporosova@intel.com>
2023-06-16 14:02:43 +04:00

39 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import logging as log
import os
import re
class TagFilter(log.Filter):
def __init__(self, regex):
"""Initialize the TagFilter with a regular expression."""
log.Filter.__init__(self)
self.regex = regex
def filter(self, record): # noqa: A003
"""Filter the log record based on the provided regex."""
if record.__dict__['funcName'] == 'load_grammar': # for nx not to log into our logs
return False
if self.regex:
if 'tag' in record.__dict__.keys():
tag = record.__dict__['tag']
return re.findall(self.regex, tag)
else:
return False
else: # if regex wasn't set, print all logs
return True
def init_logger(lvl):
"""Initialize the logger with the specified log level."""
logger = log.getLogger(__name__)
log_exp = os.environ.get('MO_LOG_PATTERN')
log.basicConfig(
format='%(levelname)s: %(module)s. %(funcName)s():%(lineno)d - %(message)s',
level=lvl,
)
logger.addFilter(TagFilter(log_exp))