Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 24, 2024
1 parent 0152579 commit e0b858c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions acceptance_tests/gunicorn_app/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ qualname = c2cwsgiutils_app

[handler_console]
class = logging.StreamHandler
kwargs = {'stream': sys.stdout}
kwargs = {'stream': 'ext://sys.stdout'}
level = NOTSET
formatter = generic

[handler_json]
class = c2cwsgiutils.pyramid_logging.JsonLogHandler
kwargs = {'stream': sys.stdout}
kwargs = {'stream': 'ext://sys.stdout'}
level = NOTSET
formatter = generic

Expand Down
4 changes: 2 additions & 2 deletions acceptance_tests/waitress_app/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ qualname = c2cwsgiutils_app

[handler_console]
class = logging.StreamHandler
kwargs = {'stream': sys.stdout}
kwargs = "{'stream': 'ext://sys.stdout'}"
level = NOTSET
formatter = generic

[handler_json]
class = c2cwsgiutils.pyramid_logging.JsonLogHandler
kwargs = {'stream': sys.stdout}
kwargs = {'stream': 'ext://sys.stdout'}
level = NOTSET
formatter = generic

Expand Down
10 changes: 10 additions & 0 deletions c2cwsgiutils/setup_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import argparse
import ast
import logging
import warnings
from typing import Any, Callable, Optional, TypedDict, cast
Expand Down Expand Up @@ -58,6 +59,7 @@ def init_logging(config_file: str = "c2c:///app/production.ini") -> None:
"""Initialize the non-WSGI application."""
warnings.warn("init_logging function is deprecated; use init instead so that all features are enabled")
loader = get_config_loader(config_file)

loader.setup_logging(None)


Expand Down Expand Up @@ -95,6 +97,14 @@ def bootstrap_application(
https://docs.pylonsproject.org/projects/pyramid/en/latest/api/paster.html?highlight=bootstrap#pyramid.paster.bootstrap
"""
loader = get_config_loader(config_uri)

handlers = [k.strip() for k in loader["handlers"]["keys"].split(",")]
for hh in handlers:
block = loader[f"handler_{hh}"]
if "kwargs" in block:
kwargs = ast.literal_eval(block["kwargs"])
block["kwargs"] = kwargs

loader.setup_logging(options)
logging.getLogger(__name__).info("Loading the application from %s", config_uri)
return cast(PyramidEnv, bootstrap(config_uri, options=options))
4 changes: 2 additions & 2 deletions production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ qualname = c2cwsgiutils

[handler_console]
class = logging.StreamHandler
kwargs = {'stream': sys.stdout}
kwargs = {'stream': 'ext://sys.stdout'}
level = NOTSET
formatter = generic

[handler_json]
class = c2cwsgiutils.pyramid_logging.JsonLogHandler
kwargs = {'stream': sys.stdout}
kwargs = {'stream': 'ext://sys.stdout'}
level = NOTSET
formatter = generic

Expand Down

0 comments on commit e0b858c

Please sign in to comment.