-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot_logger.py
27 lines (21 loc) · 922 Bytes
/
root_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from os import mkdir, path
import logging
# Create the logging directory, if necessary
logging_directory = "./logs"
if not path.exists(logging_directory):
mkdir(logging_directory)
# Set config parameters
logging.basicConfig(filename=f"{logging_directory}/greeting-cards.log",
level=logging.DEBUG,
datefmt="%Y-%m-%d %H:%M:%S",
filemode="w",
format="%(asctime)s | %(name)s | %(levelname)s | %(message)s")
# Initialize the root logger
logger = logging.getLogger()
logger.info(f"Initialized root logger at level: {logger.getEffectiveLevel()}")
# Define a global variable that indicates whether this app is running on the local machine
is_running_locally = "pycharm" in path.abspath(path.dirname(__file__)).lower()
if is_running_locally:
logger.warning("App is running locally.")
else:
logger.info("App is NOT running locally.")