Skip to content

Commit

Permalink
Merge pull request #2927 from MinchinWeb/rich-server
Browse files Browse the repository at this point in the history
Use rich logging for Pelican server
  • Loading branch information
justinmayer authored Oct 5, 2021
2 parents e2c73a0 + 2b631ab commit b5426fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pelican/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ def autoreload(args, excqueue=None):


def listen(server, port, output, excqueue=None):
# set logging level to at least "INFO" (so we can see the server requests)
if logger.level < logging.INFO:
logger.setLevel(logging.INFO)

RootedHTTPServer.allow_reuse_address = True
try:
httpd = RootedHTTPServer(
Expand All @@ -487,8 +491,8 @@ def listen(server, port, output, excqueue=None):
return

try:
print("\nServing site at: http://{}:{} - Tap CTRL-C to stop".format(
server, port))
console.print("Serving site at: http://{}:{} - Tap CTRL-C to stop".format(
server, port))
httpd.serve_forever()
except Exception as e:
if excqueue is not None:
Expand Down
4 changes: 4 additions & 0 deletions pelican/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
except ImportError:
magic_from_file = None

from pelican.log import console # noqa: F401
from pelican.log import init as init_logging
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -104,6 +105,9 @@ def guess_type(self, path):

return mimetype

def log_message(self, format, *args):
logger.info(format, *args)


class RootedHTTPServer(server.HTTPServer):
def __init__(self, base_path, *args, **kwargs):
Expand Down

0 comments on commit b5426fb

Please sign in to comment.