Skip to content

Commit

Permalink
Move logging and debug options to 'logging' section
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Nov 11, 2021
1 parent c97d70e commit b0c92c4
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
The new option `dir_browser.davmount_links` is false by default.
- Drop support for Microsoft Web Folders (option `dir_browser.ms_mount`).
- Drop support for Python syntax in config files (wsgidav.conf)
- Move logging option to 'logging' section

## 3.1.2 / Unreleased

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ Main features:
installed and run as Python command line script on Linux, OSX, and Windows:<br>
```
$ pip install wsgidav cheroot
$ wsgidav --host=0.0.0.0 --port=8080 --root=/tmp
$ wsgidav --host=0.0.0.0 --port=8080 --root=/tmp --auth=anonymous
WARNING: share '/' will allow anonymous access.
Running WsgiDAV/2.2.2 Cheroot/5.5.0 Python/3.4.2
Serving on http://0.0.0.0:8080 ...
```
Run `wsgidav --help` for a list of available options.<br>
**Note:** The syntax changed slightly with v3.0.

- **Note:** python-pam is needed if using pam-login on Linux or OSX:
```
$ pip install python-pam
$ wsgidav --auth=pam-login --host=0.0.0.0 --port=8080 --root=/tmp
```

- **Note:** Windows users may prefer the
[MSI Installer](https://github.com/mar10/wsgidav/releases/latest)
(see <kbd>Assets</kbd> section).
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/user_guide_lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ This logger can be enabled like so::
.. note::

The CLI calls :func:`util.init_logging` on startup, so it logs to stdout as configured
by the ``verbose`` and ``enable_loggers`` options.
by the ``verbose`` and ``logging.enable_loggers`` options.
37 changes: 20 additions & 17 deletions sample_wsgidav.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,26 @@ pam_dc:
#: Set verbosity level (but will be overridden by -v or -q arguments)
verbose: 3

#: Set logging output format
#: (see https://docs.python.org/3/library/logging.html#logging.Formatter)
logger_format: "%(asctime)s.%(msecs)03d - <%(thread)05d> %(name)-27s %(levelname)-8s: %(message)s"
#logger_format: "%(asctime)s.%(msecs)03d - %(levelname)-8s: %(message)s"
logger_date_format: "%H:%M:%S"
# Enable specific module loggers
# E.g. ["lock_manager", "property_manager", "http_authenticator", ...]
# enable_loggers: ["http_authenticator", ]
# Enable max. logging for certain http methods
# E.g. ["COPY", "DELETE", "GET", "HEAD", "LOCK", "MOVE", "OPTIONS", "PROPFIND", "PROPPATCH", "PUT", "UNLOCK"]
debug_methods: []
# Enable max. logging during litmus suite tests that contain certain strings
# E.g. ["lock_excl", "notowner_modify", "fail_cond_put_unlocked", ...]
debug_litmus: []
logging:
#: Set logging output format
#: (see https://docs.python.org/3/library/logging.html#logging.Formatter)
logger_date_format: "%H:%M:%S"
logger_format: "%(asctime)s.%(msecs)03d - %(levelname)-8s: %(message)s"
# Example: Add date,thread id, and logger name:
# logger_date_format: ""%Y-%m-%d %H:%M:%S"
# logger_format: "%(asctime)s.%(msecs)03d - <%(thread)05d> %(name)-27s %(levelname)-8s: %(message)s"

# Enable specific module loggers
# E.g. ["lock_manager", "property_manager", "http_authenticator", ...]
# enable_loggers: ["http_authenticator", ]

# Enable max. logging for certain http methods
# E.g. ["COPY", "DELETE", "GET", "HEAD", "LOCK", "MOVE", "OPTIONS", "PROPFIND", "PROPPATCH", "PUT", "UNLOCK"]
debug_methods: []

# Enable max. logging during litmus suite tests that contain certain strings
# E.g. ["lock_excl", "notowner_modify", "fail_cond_put_unlocked", ...]
debug_litmus: []


# ----------------------------------------------------------------------------
Expand Down
12 changes: 7 additions & 5 deletions tests/test_scripted.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ def run(self):
"http_authenticator": {"domain_controller": None},
"simple_dc": {"user_mapping": {"*": True}}, # anonymous access
"verbose": 4,
"enable_loggers": [
# "http_authenticator",
# "lock_manager",
],
"debug_methods": [],
"logging": {
"enable_loggers": [
# "http_authenticator",
# "lock_manager",
],
"debug_methods": [],
},
"property_manager": True, # True: use lock_manager.LockManager
"lock_manager": True, # True: use lock_manager.LockManager
}
Expand Down
7 changes: 6 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ def testEnablePropagation(self):

def testCliLogging(self):
"""CLI initializes logging."""
config = {"verbose": 3, "enable_loggers": ["test"]}
config = {
"verbose": 3,
"logging": {
"enable_loggers": ["test"],
},
}
init_logging(config)

_baseLogger = logging.getLogger(BASE_LOGGER_NAME)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wsgidav_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _makeWsgiDAVApp(self, withAuthentication):
"http_authenticator": {"domain_controller": None},
"simple_dc": {"user_mapping": {"*": True}}, # anonymous access
"verbose": 1,
"enable_loggers": [],
"logging": {"enable_loggers": []},
"property_manager": None, # None: no property manager
"lock_manager": True, # True: use lock_manager.LockManager
}
Expand Down
5 changes: 4 additions & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def run_wsgidav_server(with_auth, with_ssl, provider=None, **kwargs):
"http_authenticator": {"domain_controller": None},
"simple_dc": {"user_mapping": {"*": True}}, # anonymous access
"verbose": 1,
"enable_loggers": [],
"logging": {
"enable_loggers": [],
# "debug_methods": [],
},
"property_manager": True, # None: no property manager
"lock_manager": True, # True: use lock_manager.LockManager
}
Expand Down
17 changes: 9 additions & 8 deletions tests/wsgidav-litmus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ simple_dc:

verbose: 3

#logger_format: "%(asctime)s.%(msecs)03d - <%(thread)05d> %(name)-27s %(levelname)-8s: %(message)s"
#logger_date_format: "%H:%M:%S"
logging:
#logger_format: "%(asctime)s.%(msecs)03d - <%(thread)05d> %(name)-27s %(levelname)-8s: %(message)s"
#logger_date_format: "%H:%M:%S"

# Enable max. logging for certain http methods
# E.g. ["COPY", "DELETE", "GET", "HEAD", "LOCK", "MOVE", "OPTIONS", "PROPFIND", "PROPPATCH", "PUT", "UNLOCK"]
debug_methods: []
# Enable max. logging for certain http methods
# E.g. ["COPY", "DELETE", "GET", "HEAD", "LOCK", "MOVE", "OPTIONS", "PROPFIND", "PROPPATCH", "PUT", "UNLOCK"]
debug_methods: []

# Enable max. logging during litmus suite tests that contain certain strings
# E.g. ["lock_excl", "notowner_modify", "fail_cond_put_unlocked", ...]
debug_litmus: []
# Enable max. logging during litmus suite tests that contain certain strings
# E.g. ["lock_excl", "notowner_modify", "fail_cond_put_unlocked", ...]
debug_litmus: []

property_manager: true

Expand Down
5 changes: 3 additions & 2 deletions wsgidav/debug_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ class WsgiDavDebugFilter(BaseMiddleware):
def __init__(self, wsgidav_app, next_app, config):
super(WsgiDavDebugFilter, self).__init__(wsgidav_app, next_app, config)
self._config = config
log_opts = config.get("logging", {})
# self.out = sys.stdout
self.passedLitmus = {}
# These methods boost verbose=2 to verbose=3
self.debug_methods = config.get("debug_methods", [])
self.debug_methods = log_opts.get("debug_methods", [])
# Litmus tests containing these string boost verbose=2 to verbose=3
self.debug_litmus = config.get("debug_litmus", [])
self.debug_litmus = log_opts.get("debug_litmus", [])
# Exit server, as soon as this litmus test has finished
self.break_after_litmus = [
# "locks: 15",
Expand Down
26 changes: 16 additions & 10 deletions wsgidav/default_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,23 @@
},
#: Used by SimpleDomainController only
"simple_dc": {"user_mapping": {}}, # NO anonymous access by default
# Verbose Output
# 0 - no output
# 1 - no output (excepting application exceptions)
# 2 - show warnings
# 3 - show single line request summaries (for HTTP logging)
# 4 - show additional events
# 5 - show full request/response header info (HTTP Logging)
# request body and GET response bodies not shown
#: Verbose Output
#: 0 - no output
#: 1 - no output (excepting application exceptions)
#: 2 - show warnings
#: 3 - show single line request summaries (for HTTP logging)
#: 4 - show additional events
#: 5 - show full request/response header info (HTTP Logging)
#: request body and GET response bodies not shown
"verbose": DEFAULT_VERBOSE,
# Error printer options
"enable_loggers": [],
#: Log options
"logging": {
"logger_date_format": "%H:%M:%S",
"logger_format": "%(asctime)s.%(msecs)03d - %(levelname)-8s: %(message)s",
"enable_loggers": [],
"debug_methods": [],
},
#: Options for `WsgiDavDirBrowser`
"dir_browser": {
"enable": True, # Render HTML listing for GET requests on collections
# List of fnmatch patterns:
Expand Down
1 change: 0 additions & 1 deletion wsgidav/server/server_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import platform
import sys
import webbrowser
from inspect import isfunction
from pprint import pformat
from threading import Timer

Expand Down
4 changes: 3 additions & 1 deletion wsgidav/server/server_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def main():
},
"simple_dc": {"user_mapping": {"*": True}}, # anonymous access
"verbose": 1,
"enable_loggers": [],
"logging": {
"enable_loggers": [],
},
"property_manager": True, # True: use property_manager.PropertyManager
"lock_manager": True, # True: use lock_manager.LockManager
}
Expand Down
16 changes: 7 additions & 9 deletions wsgidav/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ def init_logging(config):
The base logger is filtered by the `verbose` configuration option.
Log entries will have a time stamp and thread id.
:Parameters:
verbose : int
Verbosity configuration (0..5)
enable_loggers : string list
List of module logger names, that will be switched to DEBUG level.
Module loggers
~~~~~~~~~~~~~~
Expand All @@ -211,7 +206,7 @@ def init_logging(config):
This logger would be enabled by passing its name to init_logging()::
enable_loggers = ["lock_manager",
config.logging.enable_loggers = ["lock_manager",
"property_manager",
]
util.init_logging(2, enable_loggers)
Expand Down Expand Up @@ -240,13 +235,15 @@ def init_logging(config):
"""
verbose = config.get("verbose", 3)
log_opts = config.get("logging", {})

enable_loggers = config.get("enable_loggers", [])
enable_loggers = log_opts.get("enable_loggers", [])
if enable_loggers is None:
enable_loggers = []

logger_date_format = config.get("logger_date_format", "%Y-%m-%d %H:%M:%S")
logger_format = config.get(
# Verbose format by default (but wsgidav.util.DEFAULT_CONFIG defines a short format)
logger_date_format = log_opts.get("logger_date_format", "%Y-%m-%d %H:%M:%S")
logger_format = log_opts.get(
"logger_format",
"%(asctime)s.%(msecs)03d - <%(thread)d> %(name)-27s %(levelname)-8s: %(message)s",
)
Expand Down Expand Up @@ -296,6 +293,7 @@ def init_logging(config):
e = BASE_LOGGER_NAME + "." + e
lg = logging.getLogger(e.strip())
lg.setLevel(logging.DEBUG)
return


def get_module_logger(moduleName, defaultToVerbose=False):
Expand Down
10 changes: 8 additions & 2 deletions wsgidav/wsgidav_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,31 @@ def _check_config(config):
"acceptbasic": "http_authenticator.accept_basic",
"acceptdigest": "http_authenticator.accept_digest",
"catchall": "error_printer.catch_all",
"debug_litmus": "logging.debug_litmus",
"debug_methods": "logging.debug_methods",
"defaultdigest": "http_authenticator.default_to_digest",
"dir_browser.app_class": "middleware_stack",
# "dir_browser.enable": "middleware_stack",
"dir_browser.ms_mount": "(removed)",
"dir_browser.ms_sharepoint_plugin": "dir_browser.ms_sharepoint_support",
"dir_browser.ms_sharepoint_url": "dir_browser.ms_sharepoint_support",
"dir_browser.ms_mount": "(removed)",
"domain_controller": "http_authenticator.domain_controller",
"domaincontroller": "http_authenticator.domain_controller",
"emulate_win32_lastmod": "hotfix.emulate_win32_lastmod",
"enable_loggers": "logging.enable_loggers",
"error_printer.catch_all": "(removed)",
"http_authenticator.preset_domain": "nt_dc.preset_domain",
"http_authenticator.preset_server": "nt_dc.preset_server",
"locksmanager": "lock_manager",
"logger_date_format": "logging.logger_date_format",
"logger_format": "logging.logger_format",
"logging.verbose": "verbose", # prevent a likely mistake
"mutableLiveProps": "mutable_live_props",
"propsmanager": "property_manager",
"re_encode_path_info": "hotfix.re_encode_path_info",
"trusted_auth_header": "http_authenticator.trusted_auth_header",
"unquote_path_info": "hotfix.unquote_path_info",
"user_mapping": "simple_dc.user_mapping",
# "dir_browser.enable": "middleware_stack",
}
for old, new in deprecated_fields.items():
if "." in old:
Expand Down

0 comments on commit b0c92c4

Please sign in to comment.