Skip to content

Commit 64cea45

Browse files
committed
logging change and app.py -> main.py
1 parent 6e3c7c6 commit 64cea45

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/helper_logging.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
"""Helper: Logging."""
22

3+
import logging
34
import time
45
from collections import defaultdict
56
from collections.abc import Callable
67
from functools import wraps
7-
from logging import Logger
88
from pathlib import Path
99

1010
import streamlit as st
11-
from streamlit.logger import get_logger
1211

1312

14-
def get_logger_from_filename(file: str) -> Logger:
13+
def init_logging() -> None:
14+
"""Initialize and and configure the logging."""
15+
logging.addLevelName(logging.DEBUG, "D")
16+
logging.addLevelName(logging.INFO, "I")
17+
logging.addLevelName(logging.WARNING, "W")
18+
logging.addLevelName(logging.ERROR, "E")
19+
logging.addLevelName(logging.CRITICAL, "C")
20+
logging.basicConfig(
21+
level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s"
22+
)
23+
24+
25+
def get_logger_from_filename(file: str) -> logging.Logger:
1526
"""Return logger using filename name."""
1627
page = Path(file).stem
17-
if page != "app" and not page.startswith("helper_"):
28+
if page != "main" and not page.startswith("helper_"):
1829
d = get_page_count()
1930
d[page] = d.get(page, 0) + 1
20-
return get_logger(page)
31+
return logging.getLogger(page)
2132

2233

2334
@st.cache_resource

src/app.py renamed to src/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
# needs to be first streamlit command, so placed before the imports
1111
st.set_page_config(page_title="Strava Äpp V2", page_icon=None, layout="wide")
1212

13-
from helper_logging import get_logger_from_filename, get_user_login_count
13+
from helper_logging import get_logger_from_filename, get_user_login_count, init_logging
1414
from helper_login import (
1515
perform_login,
1616
token_refresh_if_needed,
1717
)
1818
from helper_ui_components import create_navigation_menu
1919

2020
MEASURE_MEMORY = True
21+
init_logging()
2122
logger = get_logger_from_filename(__file__)
2223

2324

@@ -106,6 +107,8 @@ def main() -> None: # noqa: D103
106107
time_start = time()
107108
pagename = create_navigation_menu()
108109
time_end = time()
110+
if pagename == "":
111+
pagename = "main"
109112
log_line = f"stats: {pagename},{round(time_end - time_start, 1)}s"
110113

111114
if MEASURE_MEMORY:

0 commit comments

Comments
 (0)