From e6a835fd794a95e1aa58079193f31661999030a2 Mon Sep 17 00:00:00 2001 From: Anton Joubert <ajoubert@ska.ac.za> Date: Mon, 13 Jan 2020 14:50:26 +0200 Subject: [PATCH] SAR-55 Revert add static tag to formatter Turns out this is not that useful for Tango SKABaseDevice. --- ska_logging/__init__.py | 4 ---- ska_logging/configuration.py | 33 ++++----------------------------- tests/test_configuration.py | 15 +-------------- 3 files changed, 5 insertions(+), 47 deletions(-) diff --git a/ska_logging/__init__.py b/ska_logging/__init__.py index 1dcf20a..8d77cde 100644 --- a/ska_logging/__init__.py +++ b/ska_logging/__init__.py @@ -5,8 +5,6 @@ __all__ = ( "configure_logging", "get_default_formatter", - "SkaLoggingError", - "SkaLoggingTagsFormatError", ) __author__ = "Anton Joubert" __email__ = "ajoubert+ska@ska.ac.za" @@ -15,8 +13,6 @@ __email__ = "ajoubert+ska@ska.ac.za" from .configuration import ( configure_logging, get_default_formatter, - SkaLoggingError, - SkaLoggingTagsFormatError, ) diff --git a/ska_logging/configuration.py b/ska_logging/configuration.py index 11135f3..22c6a26 100644 --- a/ska_logging/configuration.py +++ b/ska_logging/configuration.py @@ -7,14 +7,6 @@ import logging.config import time -class SkaLoggingError(Exception): - """Base class for all SKA Logger exceptions.""" - - -class SkaLoggingTagsFormatError(SkaLoggingError): - """Invalid format for the 'tags' field string.""" - - class _UTCFormatter(logging.Formatter): converter = time.gmtime @@ -46,7 +38,6 @@ _FORMAT_STR_WITH_TAGS = ( "%(message)s" ) -_INVALID_TAG_CHARS = ("|", "%") _LOGGING_CONFIG = { "version": 1, @@ -123,33 +114,17 @@ def get_default_formatter(tags=False): Parameters ---------- - tags : bool or str, optional - If boolean, then treated as a toggle: - - True: include the "tags" field in the format string. This requires - a tags filter to be linked to the corresponding handler. - - False: exclude the "tags" field from the format string. - If string, then it is a static tag. Instead of using a logging filter, the - formatter will just use this static string for the "tags" field directly. + tags : bool, optional + If true, then include the "tags" field in the format string. This requires + a tags filter to be linked to the corresponding handler. Returns ------- logging.Formatter A new default formatter. - Raises - ------ - SkaLoggingTagsFormatError: - If the static tags string has an invalid format. - """ - if isinstance(tags, str): - invalid_chars = [c for c in _INVALID_TAG_CHARS if c in tags] - if invalid_chars: - raise SkaLoggingTagsFormatError( - "Invalid char(s) {} in tags: {!r}".format(invalid_chars, tags) - ) - format_str = _FORMAT_STR_WITH_TAGS.replace("%(tags)s", tags) - elif tags: + if tags: format_str = _FORMAT_STR_WITH_TAGS else: format_str = _FORMAT_STR_NO_TAGS diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 3e72a36..885cc80 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -9,7 +9,7 @@ import pytest import ska_logging.configuration -from ska_logging import configure_logging, get_default_formatter, SkaLoggingTagsFormatError +from ska_logging import configure_logging, get_default_formatter @pytest.fixture @@ -183,19 +183,6 @@ class TestGetDefaultFormatter: assert isinstance(formatter, ska_logging.configuration._UTCFormatter) assert formatter._fmt == ska_logging.configuration._FORMAT_STR_WITH_TAGS - def test_get_tags_static_string(self): - formatter = get_default_formatter(tags="test-key:test-value") - assert isinstance(formatter, ska_logging.configuration._UTCFormatter) - tags_format = ska_logging.configuration._FORMAT_STR_WITH_TAGS - expected_format = tags_format.replace("%(tags)s", "test-key:test-value") - assert formatter._fmt == expected_format - - def test_get_tags_invalid_static_string(self): - with pytest.raises(SkaLoggingTagsFormatError): - get_default_formatter(tags="no|pipes|allowed") - with pytest.raises(SkaLoggingTagsFormatError): - get_default_formatter(tags="no%percentage%symbols%allowed") - class TestOverride: """Tests for :func:`~ska_logging.configuration._override`. -- GitLab