Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sphinx logger #3832

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/iris/analysis/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from functools import lru_cache
import inspect
import logging
import math
import operator
import warnings
Expand All @@ -23,14 +22,15 @@
import iris.analysis
from iris.common import SERVICES, Resolve
from iris.common.lenient import _lenient_client
from iris.config import get_logger
import iris.coords
import iris.cube
import iris.exceptions
import iris.util


# Configure the logger.
logger = logging.getLogger(__name__)
logger = get_logger(__name__)


@lru_cache(maxsize=128, typed=True)
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from collections.abc import Iterable, Mapping
from copy import deepcopy
from functools import wraps
import logging
import re

import numpy as np
import numpy.ma as ma
from xxhash import xxh64_hexdigest

from ..config import get_logger
from .lenient import _LENIENT
from .lenient import _lenient_service as lenient_service
from .lenient import _qualname as qualname
Expand All @@ -40,7 +40,7 @@
_TOKEN_PARSE = re.compile(r"""^[a-zA-Z0-9][\w\.\+\-@]*$""")

# Configure the logger.
logger = logging.getLogger(__name__)
logger = get_logger(__name__, fmt="[%(cls)s.%(funcName)s]")


def _hexdigest(value):
Expand Down
5 changes: 3 additions & 2 deletions lib/iris/common/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
from dask.array.core import broadcast_shapes
import numpy as np

from iris.common import LENIENT
from ..config import get_logger
from . import LENIENT


__all__ = ["Resolve"]


# Configure the logger.
logger = logging.getLogger(__name__)
logger = get_logger(__name__, fmt="[%(funcName)s]")


_AuxCoverage = namedtuple(
Expand Down
81 changes: 69 additions & 12 deletions lib/iris/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,77 @@

import configparser
import contextlib
import logging.config
import logging
import os.path
import pathlib
import warnings
import yaml


def get_logger(name, datefmt=None, fmt=None, level=None, propagate=None):
"""
Create a :class:`logging.Logger` with a :class:`logging.StreamHandler`
and custom :class:`logging.Formatter`.

Args:

* name:
The name of the logger. Typically this is the module filename that
owns the logger.

Kwargs:

* datefmt:
The date format string of the :class:`logging.Formatter`.
Defaults to ``%d-%m-%Y %H:%M:%S``.

* fmt:
The additional format string of the :class:`logging.Formatter`.
This is appended to the default format string
``%(asctime)s %(name)s %(levelname)s - %(message)s``.

* level:
The threshold level of the logger. Defaults to ``INFO``.

* propagate:
Sets the ``propagate`` attribute of the :class:`logging.Logger`,
which determines whether events logged to this logger will be
passed to the handlers of higher level loggers. Defaults to
``False``.

"""
if datefmt is None:
# Default date format string.
datefmt = "%d-%m-%Y %H:%M:%S"

# Default format string.
_fmt = "%(asctime)s %(name)s %(levelname)s - %(message)s"
# Append additional format string, if appropriate.
fmt = _fmt if fmt is None else f"{_fmt} {fmt}"

if level is None:
# Default logging level.
level = "INFO"

if propagate is None:
# Default logging propagate behaviour.
propagate = False

# Create the named logger.
logger = logging.getLogger(name)
logger.setLevel(level)
logger.propagate = propagate

# Create a formatter.
formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)

# Create a logging handler.
handler = logging.StreamHandler()
# handler.setLevel(level)
handler.setFormatter(formatter)

# Add the handler to the logger.
logger.addHandler(handler)

return logger


# Returns simple string options
Expand Down Expand Up @@ -84,15 +150,6 @@ def get_dir_option(section, option, default=None):
config = configparser.ConfigParser()
config.read([os.path.join(CONFIG_PATH, "site.cfg")])

# Configure logging.
fname_logging = pathlib.Path(CONFIG_PATH) / "logging.yaml"
if not fname_logging.exists():
emsg = f"Logging configuration file '{fname_logging!s}' does not exist."
raise FileNotFoundError(emsg)
with open(fname_logging) as fi:
logging.config.dictConfig(yaml.safe_load(fi))
del fname_logging

##################
# Resource options
_RESOURCE_SECTION = "Resources"
Expand Down
45 changes: 0 additions & 45 deletions lib/iris/etc/logging.yaml

This file was deleted.