diff options
author | Vratko Polak <vrpolak@cisco.com> | 2019-07-17 12:40:49 +0200 |
---|---|---|
committer | Vratko Polak <vrpolak@cisco.com> | 2019-07-17 12:40:49 +0200 |
commit | f88a3d9178dfbd73d0479f9aa2f5224e0c89ca1f (patch) | |
tree | 9963cb06a7f089d815f9ebf5e5ba8d8f1f26a209 /resources/libraries/python/FilteredLogger.py | |
parent | 248d1a52e06622dc9eb1dfdd6ca9f6670b4c0bc3 (diff) |
Use PapiSocketProvider for most PAPI calls
Ticket: CSIT-1541
Ticket: VPP-1722
Ticket: CSIT-1546
+ Increase timeout to hide x520 slownes of show hardware detail.
- Install sshpass and update ssh client in virl bootstrap.
+ Added TODOs to remove when CSIT-1546 is fixed.
+ Enable default socksvr on any startup conf.
+ Improve OptionString init and repr.
- The non-socket executor still kept for stats.
+ Remove everything unrelated to stats from non-socket executor.
- Remove some debug-loooking calls to avoid failures.
TODO: Introduce proper parsing to the affected keywords.
+ Reduce logging from PAPI code to level INFO.
- Needs https://gerrit.fd.io/r/20660 to fully work.
+ Change default values for LocalExecution.run()
+ Return code check enabled by default.
Code is more readable when rc!=0 is allowed explicitly,
and the test code will now detect unexpected failures.
+ Logging disabled by default.
Output XML is large already. Important logging can be enabled explicitly.
+ Restore alphabetical order in common.sh functions.
Change-Id: I05882cb6b620ad14638f7404b5ad38c7a5de9e6c
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
Diffstat (limited to 'resources/libraries/python/FilteredLogger.py')
-rw-r--r-- | resources/libraries/python/FilteredLogger.py | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/resources/libraries/python/FilteredLogger.py b/resources/libraries/python/FilteredLogger.py new file mode 100644 index 0000000000..a04eb67476 --- /dev/null +++ b/resources/libraries/python/FilteredLogger.py @@ -0,0 +1,95 @@ +# Copyright (c) 2019 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Python library for customizing robot.api.logger + +As robot.api.logger is a module, it is not easy to copy, edit or inherit from. +This module offers a class to wrap it. +The main point of the class is to lower verbosity of Robot logging, +especially when injected to third party code (such as vpp_papi.VPPApiClient). + +Also, String formatting using '%' operator is supported. + +Logger.console() is not supported. +""" + +import logging + +_LEVELS = { + "TRACE": logging.DEBUG // 2, + "DEBUG": logging.DEBUG, + "INFO": logging.INFO, + "HTML": logging.INFO, + "WARN": logging.WARN, + "ERROR": logging.ERROR, + "CRITICAL": logging.CRITICAL, + "NONE": logging.CRITICAL, +} + +class FilteredLogger(object): + """Instances of this class have the similar API to robot.api.logger. + + TODO: Support html argument? + TODO: Support console with a filtering switch? + """ + + def __init__(self, logger_module, min_level="INFO"): + """Remember the values, check min_level is known. + + Use min_level of "CRITICAL" or "NONE" to disable logging entirely. + + :param logger_module: robot.api.logger, or a compatible object. + :param min_level: Minimal level to log, lower levels are ignored. + :type logger_module: Object with .write(msg, level="INFO") signature. + :type min_level: str + :raises KeyError: If given min_level is not supported. + """ + self.logger_module = logger_module + self.min_level_num = _LEVELS[min_level.upper()] + + def write(self, message, farg=None, level="INFO"): + """Forwards the message to logger if min_level is reached. + + Formatting using '%' operator is used when farg argument is suplied. + + :param message: Message to log. + :param farg: Value for '%' operator, or None. + :param level: Level to possibly log with. + :type message: str + :type farg: NoneTye, or whatever '%' accepts: str, int, float, dict... + :type level: str + """ + if _LEVELS[level.upper()] >= self.min_level_num: + if farg is not None: + message = message % farg + self.logger_module.write(message, level=level) + + def trace(self, message, farg=None): + """Forward the message using the ``TRACE`` level.""" + self.write(message, farg=farg, level="TRACE") + + def debug(self, message, farg=None): + """Forward the message using the ``DEBUG`` level.""" + self.write(message, farg=farg, level="DEBUG") + + def info(self, message, farg=None): + """Forward the message using the ``INFO`` level.""" + self.write(message, farg=farg, level="INFO") + + def warn(self, message, farg=None): + """Forward the message using the ``WARN`` level.""" + self.write(message, farg=farg, level="WARN") + + def error(self, message, farg=None): + """Forward the message using the ``ERROR`` level.""" + self.write(message, farg=farg, level="ERROR") |