-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlogs.py
38 lines (31 loc) · 1.15 KB
/
logs.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
28
29
30
31
32
33
34
35
36
37
38
import logging
import logging.handlers
"""
This module sets up logging for the AutoAquaponics system.
# Function
`setup_logger(log_file, subsystem_name)`
Configures and returns a logger for a given subsystem.
# Variables
- `_global_log_file: str`: The default log file name for the global logger.
- `global_logger: logging.Logger`: The global logger instance for the
AutoAquaponics system. This is instantiated when this module is first
imported, and other modules can import this logger and use it to log
messages.
"""
def setup_logger(log_file, subsystem_name):
logger = logging.getLogger(subsystem_name)
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"%(asctime)s %(levelname)s in module `%(module)s`: %(message)s",
)
handler = logging.handlers.TimedRotatingFileHandler(
log_file,
when="midnight",
backupCount=30,
)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
_global_log_file = "logs/autoaquaponics.log"
global_logger = setup_logger(_global_log_file, "AutoAquaponics System")
global_logger.info("logger setup complete")