Skip to content

Commit

Permalink
remove root loggers (geopython#923) (geopython#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis authored Jun 6, 2024
1 parent 13b0050 commit 44e3ece
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 192 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ Map Tile Service (WMTS). Some of those are beta quality.

Logging
-------
OWSLib logs messages to the 'owslib' named Python logger. You may
OWSLib logs messages to module-based named Python loggers. You may
configure your application to use the log messages like so:

```python
>>> import logging
>>> owslib_log = logging.getLogger('owslib')
>>> LOGGER = logging.getLogger(__name__)
>>> # Add formatting and handlers as needed, for example to log to the console
>>> ch = logging.StreamHandler()
>>> ch.setLevel(logging.DEBUG)
>>> ch.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
>>> # add the handler to the logger
>>> owslib_log.addHandler(ch)
>>> owslib_log.setLevel(logging.DEBUG)
>>> LOGGER.addHandler(ch)
>>> LOGGER.setLevel(logging.DEBUG)
```

Releasing
Expand Down
22 changes: 12 additions & 10 deletions owslib/coverage/wcs100.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
# Copyright (c) 2004, 2006 Sean C. Gillies
# Copyright (c) 2007 STFC <http://www.stfc.ac.uk>
#
# Authors :
# Authors:
# Dominic Lowe <[email protected]>
#
# Contact email: [email protected]
# =============================================================================

from owslib.coverage.wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from urllib.parse import urlencode
from owslib.util import openURL, testXMLValue
from owslib.etree import etree
from owslib.crs import Crs
import os
import errno
import logging
from urllib.parse import urlencode

from owslib.coverage.wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from owslib.crs import Crs
from owslib.etree import etree
from owslib.util import makeString, openURL, testXMLValue

from owslib.util import log, makeString
LOGGER = logging.getLogger(__name__)


# function to save writing out WCS namespace in full each time
Expand Down Expand Up @@ -108,7 +110,7 @@ def getCoverage(self, identifier=None, bbox=None, time=None, format=None, crs=No
"""
msg = 'WCS 1.0.0 DEBUG: Parameters passed to GetCoverage: identifier={}, bbox={}, time={}, format={}, crs={}, width={}, height={}, resx={}, resy={}, resz={}, parameter={}, method={}, other_arguments={}' # noqa
log.debug(msg.format(
LOGGER.debug(msg.format(
identifier, bbox, time, format, crs, width, height, resx, resy, resz, parameter, method, str(kwargs)))

try:
Expand All @@ -117,7 +119,7 @@ def getCoverage(self, identifier=None, bbox=None, time=None, format=None, crs=No
except StopIteration:
base_url = self.url

log.debug('WCS 1.0.0 DEBUG: base url of server: %s' % base_url)
LOGGER.debug('WCS 1.0.0 DEBUG: base url of server: %s' % base_url)

# process kwargs
request = {'version': self.version, 'request': 'GetCoverage', 'service': 'WCS'}
Expand Down Expand Up @@ -151,7 +153,7 @@ def getCoverage(self, identifier=None, bbox=None, time=None, format=None, crs=No

# encode and request
data = urlencode(request)
log.debug('WCS 1.0.0 DEBUG: Second part of URL: %s' % data)
LOGGER.debug('WCS 1.0.0 DEBUG: Second part of URL: %s' % data)

u = openURL(base_url, data, method, self.cookies, auth=self.auth, timeout=timeout, headers=self.headers)
return u
Expand Down
18 changes: 9 additions & 9 deletions owslib/coverage/wcs110.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
# Copyright (c) 2004, 2006 Sean C. Gillies
# Copyright (c) 2007 STFC <http://www.stfc.ac.uk>
#
# Authors :
# Authors:
# Dominic Lowe <[email protected]>
#
# Contact email: [email protected]
# =============================================================================

# NOTE: Does not conform to new interfaces yet #################

from .wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from owslib.util import openURL, testXMLValue
import errno
import logging
import os
from urllib.parse import urlencode

from .wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from owslib.etree import etree
import os
import errno
from owslib.coverage import wcsdecoder
from owslib.crs import Crs
from owslib.util import openURL, testXMLValue

import logging
from owslib.util import log

LOGGER = logging.getLogger(__name__)

class Namespaces_1_1_0():

Expand Down Expand Up @@ -157,7 +157,7 @@ def getCoverage(self, identifier=None, bbox=None, time=None, format=None, store=
if store = false, returns a multipart mime
"""
msg = 'WCS 1.1.0 DEBUG: Parameters passed to GetCoverage: identifier={}, bbox={}, time={}, format={}, rangesubset={}, gridbaseCRS={}, gridtype={}, gridCS={}, gridorigin={}, gridoffsets={}, method={}, other_arguments={}' # noqa
log.debug(msg.format(
LOGGER.debug(msg.format(
identifier, bbox, time, format, rangesubset, gridbaseCRS, gridtype, gridCS,
gridorigin, gridoffsets, method, str(kwargs)))

Expand Down
35 changes: 18 additions & 17 deletions owslib/coverage/wcs200.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@
# Copyright (c) 2004, 2006 Sean C. Gillies
# Copyright (c) 2007 STFC <http://www.stfc.ac.uk>
#
# Authors :
# Authors:
# Oliver Clements <[email protected]>
#
# Contact email: [email protected]
# =============================================================================

# !!! NOTE: Does not conform to new interfaces yet #################

from datetime import timedelta
import errno
import logging
import os
from urllib.parse import urlencode

import dateutil.parser as parser

from owslib.coverage.wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from owslib.crs import Crs
from owslib.etree import etree
from owslib.ows import (
OwsCommon,
ServiceIdentification,
ServiceProvider,
OperationsMetadata,
OperationsMetadata
)
from owslib.util import datetime_from_ansi, datetime_from_iso, openURL, param_list_to_url_string, testXMLValue

from urllib.parse import urlencode
from owslib.util import openURL, testXMLValue
from owslib.etree import etree
from owslib.crs import Crs
import os
import errno
import dateutil.parser as parser
from datetime import timedelta
import logging
from owslib.util import log, datetime_from_ansi, datetime_from_iso, param_list_to_url_string
LOGGER = logging.getLogger(__name__)


# function to save writing out WCS namespace in full each time
Expand Down Expand Up @@ -153,7 +154,7 @@ def getCoverage(
"""
log.debug(
LOGGER.debug(
"WCS 2.0.0 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, crs=%s, width=%s, height=%s, resx=%s, resy=%s, resz=%s, parameter=%s, method=%s, other_arguments=%s" # noqa
% (
identifier,
Expand Down Expand Up @@ -183,7 +184,7 @@ def getCoverage(
except StopIteration:
base_url = self.url

log.debug("WCS 2.0.0 DEBUG: base url of server: %s" % base_url)
LOGGER.debug("WCS 2.0.0 DEBUG: base url of server: %s" % base_url)

request = {"version": self.version, "request": "GetCoverage", "service": "WCS"}
assert len(identifier) > 0
Expand All @@ -207,12 +208,12 @@ def getCoverage(
if subsets:
data += param_list_to_url_string(subsets, 'subset')
if resolutions:
log.debug('Adding vendor-specific RESOLUTION parameter.')
LOGGER.debug('Adding vendor-specific RESOLUTION parameter.')
data += param_list_to_url_string(resolutions, 'resolution')
if sizes:
log.debug('Adding vendor-specific SIZE parameter.')
LOGGER.debug('Adding vendor-specific SIZE parameter.')
data += param_list_to_url_string(sizes, 'size')
log.debug("WCS 2.0.0 DEBUG: Second part of URL: %s" % data)
LOGGER.debug("WCS 2.0.0 DEBUG: Second part of URL: %s" % data)

u = openURL(base_url, data, method, self.cookies, auth=self.auth, timeout=timeout, headers=self.headers)
return u
Expand Down
35 changes: 17 additions & 18 deletions owslib/coverage/wcs201.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@
# Copyright (c) 2004, 2006 Sean C. Gillies
# Copyright (c) 2007 STFC <http://www.stfc.ac.uk>
#
# Authors :
# Authors:
# Oliver Clements <[email protected]>
#
# Contact email: [email protected]
# =============================================================================

# !!! NOTE: Does not conform to new interfaces yet #################

import os
from datetime import timedelta
import errno
import logging
from urllib.parse import urlencode

import dateutil.parser as parser

from owslib.coverage.wcsBase import WCSBase, WCSCapabilitiesReader, ServiceException
from owslib.etree import etree
from owslib.crs import Crs
from owslib.ows import (
OwsCommon,
ServiceIdentification,
ServiceProvider,
OperationsMetadata,
OperationsMetadata
)

from urllib.parse import urlencode
from owslib.util import openURL, testXMLValue
from owslib.etree import etree
from owslib.crs import Crs
import os
import errno
import dateutil.parser as parser
from datetime import timedelta
import logging
from owslib.util import log, datetime_from_ansi, datetime_from_iso, param_list_to_url_string
from owslib.util import datetime_from_ansi, datetime_from_iso, openURL, param_list_to_url_string, testXMLValue


# function to save writing out WCS namespace in full each time
Expand Down Expand Up @@ -153,7 +152,7 @@ def getCoverage(
"""
log.debug(
LOGGER.debug(
"WCS 2.0.1 DEBUG: Parameters passed to GetCoverage: identifier=%s, bbox=%s, time=%s, format=%s, crs=%s, width=%s, height=%s, resx=%s, resy=%s, resz=%s, parameter=%s, method=%s, other_arguments=%s" # noqa
% (
identifier,
Expand Down Expand Up @@ -183,7 +182,7 @@ def getCoverage(
except StopIteration:
base_url = self.url

log.debug("WCS 2.0.1 DEBUG: base url of server: %s" % base_url)
LOGGER.debug("WCS 2.0.1 DEBUG: base url of server: %s" % base_url)

request = {"version": self.version, "request": "GetCoverage", "service": "WCS"}
assert len(identifier) > 0
Expand All @@ -207,13 +206,13 @@ def getCoverage(
if subsets:
data += param_list_to_url_string(subsets, 'subset')
if resolutions:
log.debug('Adding vendor-specific RESOLUTION parameter.')
LOGGER.debug('Adding vendor-specific RESOLUTION parameter.')
data += param_list_to_url_string(resolutions, 'resolution')
if sizes:
log.debug('Adding vendor-specific SIZE parameter.')
LOGGER.debug('Adding vendor-specific SIZE parameter.')
data += param_list_to_url_string(sizes, 'size')

log.debug("WCS 2.0.1 DEBUG: Second part of URL: %s" % data)
LOGGER.debug("WCS 2.0.1 DEBUG: Second part of URL: %s" % data)

u = openURL(base_url, data, method, self.cookies, auth=self.auth, timeout=timeout, headers=self.headers)
return u
Expand Down
10 changes: 7 additions & 3 deletions owslib/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
#
# =============================================================================

import logging

from urllib.parse import urlencode
from owslib.crs import Crs
from owslib.util import log, Authentication
from owslib.util import Authentication
from owslib.feature.schema import get_schema
from owslib.feature.postrequest import PostRequest_1_1_0, PostRequest_2_0_0

LOGGER = logging.getLogger(__name__)


class WebFeatureService_(object):
"""Base class for WebFeatureService implementations"""
Expand Down Expand Up @@ -137,7 +141,7 @@ def getSRS(self, srsname, typename):
return self.contents[typename].crsOptions[index]
except ValueError:
options = ", ".join([crs.id for crs in self.contents[typename].crsOptions])
log.warning(
LOGGER.warning(
"Requested srsName %r is not declared as being "
"allowed for requested typename %r. "
"Options are: %r.",
Expand Down Expand Up @@ -326,7 +330,7 @@ def getPOSTGetFeatureRequest(

if storedQueryID:
if self.version in ["1.0.0", "1.1.0"]:
log.warning("Stored queries are only supported in version 2.0.0 and above.")
LOGGER.warning("Stored queries are only supported in version 2.0.0 and above.")
return None

storedQueryParams = storedQueryParams or {}
Expand Down
16 changes: 7 additions & 9 deletions owslib/feature/wfs100.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
# $Id: wfs.py 503 2006-02-01 17:09:12Z dokai $
# =============================================================================

from io import BytesIO
import itertools
import logging

from owslib import util

from io import BytesIO
from urllib.parse import urlencode

from owslib.util import (
nspath_eval,
testXMLValue,
extract_xml_list,
ServiceException,
xmltag_split,
Authentication,
openURL,
log,
openURL
)
from owslib.etree import etree
from owslib.fgdc import Metadata
Expand Down Expand Up @@ -296,7 +294,7 @@ def getfeature(
request["outputFormat"] = outputFormat

data = urlencode(request)
log.debug("Making request: %s?%s" % (base_url, data))
LOGGER.debug("Making request: %s?%s" % (base_url, data))
u = openURL(base_url, data, method, timeout=self.timeout,
headers=self.headers, auth=self.auth)

Expand Down Expand Up @@ -464,9 +462,9 @@ def parse_remote_metadata(self, timeout=30):
metadataUrl["metadata"] = None
elif metadataUrl["type"] == "TC211":
mdelem = doc.find(
".//" + util.nspath_eval("gmd:MD_Metadata", n.get_namespaces(["gmd"]))
".//" + nspath_eval("gmd:MD_Metadata", n.get_namespaces(["gmd"]))
) or doc.find(
".//" + util.nspath_eval("gmi:MI_Metadata", n.get_namespaces(["gmi"]))
".//" + nspath_eval("gmi:MI_Metadata", n.get_namespaces(["gmi"]))
)
if mdelem is not None:
metadataUrl["metadata"] = MD_Metadata(mdelem)
Expand Down
Loading

0 comments on commit 44e3ece

Please sign in to comment.