Skip to content

Commit 69b30f7

Browse files
author
michaelyaakoby
authored
Merge pull request #32 from SolarEdgeTech/yanay-fix-issue-31-app-logging-conf
Initialize logging before Pyctuator
2 parents 1d71706 + b3ef885 commit 69b30f7

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

examples/Advanced/advanced_example_app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def recursive_get(child_conf: Dict, key_parts: List[str]) -> Any:
6767
# A FastAPI application is initialized providing some test API
6868
# ----------------------------------------------------------------------------------------------------------------------
6969

70-
logging.basicConfig(level=logging.INFO)
7170
logger = logging.getLogger("ExampleApp")
7271

7372
# Initialize a connection to the DB which the app is using

examples/FastAPI/fastapi_example_app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from pyctuator.pyctuator import Pyctuator
1010

11-
logging.basicConfig(level=logging.INFO)
1211
my_logger = logging.getLogger("example")
1312

1413
app = FastAPI(

examples/Flask/flask_example_app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from pyctuator.pyctuator import Pyctuator
88

9-
logging.basicConfig(level=logging.INFO)
10-
119
# Keep the console clear - configure werkzeug (flask's WSGI web app) not to log the detail of every incoming request
1210
logging.getLogger("werkzeug").setLevel(logging.WARNING)
1311

examples/aiohttp/aiohttp_example_app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from pyctuator.pyctuator import Pyctuator
88

9-
logging.basicConfig(level=logging.INFO)
109
my_logger = logging.getLogger("example")
1110
app = web.Application()
1211
routes = web.RouteTableDef()

pyctuator/pyctuator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def __init__(
8989
self.boot_admin_registration_handler: Optional[BootAdminRegistrationHandler] = None
9090

9191
root_logger = logging.getLogger()
92+
# If application did not initiate logging module, add default handler to root logger
93+
# logging.info implicitly calls logging.basicConfig(), see logging.basicConfig in Python's documentation.
94+
if not root_logger.hasHandlers():
95+
logging.info("Logging not configured, using logging.basicConfig()")
96+
9297
root_logger.addHandler(self.pyctuator_impl.logfile.log_messages)
9398

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

0 commit comments

Comments
 (0)