Skip to content

Commit

Permalink
Merge pull request #32 from SolarEdgeTech/yanay-fix-issue-31-app-logg…
Browse files Browse the repository at this point in the history
…ing-conf

Initialize logging before Pyctuator
  • Loading branch information
michaelyaakoby authored Sep 2, 2020
2 parents 1d71706 + b3ef885 commit 69b30f7
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
1 change: 0 additions & 1 deletion examples/Advanced/advanced_example_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def recursive_get(child_conf: Dict, key_parts: List[str]) -> Any:
# A FastAPI application is initialized providing some test API
# ----------------------------------------------------------------------------------------------------------------------

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("ExampleApp")

# Initialize a connection to the DB which the app is using
Expand Down
1 change: 0 additions & 1 deletion examples/FastAPI/fastapi_example_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from pyctuator.pyctuator import Pyctuator

logging.basicConfig(level=logging.INFO)
my_logger = logging.getLogger("example")

app = FastAPI(
Expand Down
2 changes: 0 additions & 2 deletions examples/Flask/flask_example_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from pyctuator.pyctuator import Pyctuator

logging.basicConfig(level=logging.INFO)

# Keep the console clear - configure werkzeug (flask's WSGI web app) not to log the detail of every incoming request
logging.getLogger("werkzeug").setLevel(logging.WARNING)

Expand Down
1 change: 0 additions & 1 deletion examples/aiohttp/aiohttp_example_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from pyctuator.pyctuator import Pyctuator

logging.basicConfig(level=logging.INFO)
my_logger = logging.getLogger("example")
app = web.Application()
routes = web.RouteTableDef()
Expand Down
5 changes: 5 additions & 0 deletions pyctuator/pyctuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def __init__(
self.boot_admin_registration_handler: Optional[BootAdminRegistrationHandler] = None

root_logger = logging.getLogger()
# If application did not initiate logging module, add default handler to root logger
# logging.info implicitly calls logging.basicConfig(), see logging.basicConfig in Python's documentation.
if not root_logger.hasHandlers():
logging.info("Logging not configured, using logging.basicConfig()")

root_logger.addHandler(self.pyctuator_impl.logfile.log_messages)

# Find and initialize an integration layer between the web-framework adn pyctuator
Expand Down

0 comments on commit 69b30f7

Please sign in to comment.