-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import logging | ||
import os | ||
#dynamically generates logger objects and log files based on the number of sources and sinks and stores all loggers in a dictionary accessed with the filename without .py | ||
#so for example the file "sinks/dashboard/main.py" would be accessed with "dashboard" | ||
|
||
def init_loggers(): | ||
#initializes variable to be returned | ||
loggers = dict([]) | ||
|
||
#generates logger objects and log files for each source | ||
for filename in os.listdir("sources"): | ||
os.makedirs(os.path.dirname(f'logs/sources/{filename}.log'), exist_ok=True) | ||
logger = logging.getLogger(filename) | ||
logger.setLevel("INFO") | ||
|
||
handler = logging.FileHandler(f"logs/sources/{filename}.log", mode='w') | ||
formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s') | ||
handler.setFormatter(formatter) | ||
|
||
logger.addHandler(handler) | ||
loggers.update({filename: logger}) | ||
|
||
#generates logger objects and log files for each sink | ||
for filename in os.listdir("sinks"): | ||
os.makedirs(os.path.dirname(f'logs/sinks/{filename}.log'), exist_ok=True) | ||
logger = logging.getLogger(filename) | ||
logger.setLevel("INFO") | ||
|
||
handler = logging.FileHandler(f"logs/sinks/{filename}.log", mode='w') | ||
formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s') | ||
handler.setFormatter(formatter) | ||
|
||
logger.addHandler(handler) | ||
loggers.update({filename: logger}) | ||
|
||
#generates a misc logger and log file in case there is an output or error from neither a sink nor a source | ||
os.makedirs(os.path.dirname(f'logs/other.log'), exist_ok=True) | ||
logger = logging.getLogger("other") | ||
logger.setLevel("INFO") | ||
|
||
handler = logging.FileHandler(f"logs/other.log", mode='w') | ||
formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s') | ||
handler.setFormatter(formatter) | ||
|
||
logger.addHandler(handler) | ||
loggers.update({"other": logger}) | ||
|
||
return loggers |