pybatmesh/naxalnet/log.py

39 lines
923 B
Python
Raw Normal View History

"""
log.py
------
Initialise the logger for other submodules to import. Do not
import any submodules here except for naxallnet.config
"""
import logging
from systemd.journal import JournalHandler
from naxalnet.config import args
def get_logger():
"""
Initialise the logger and return it.
This function is meant to be used only by naxalnet.log.
If you want to import the logger, use:
from naxalnet.log import logger
"""
log = logging.getLogger("naxalnet")
# --verbose
if args.verbose >= 2:
loglevel = logging.DEBUG
elif args.verbose == 1:
loglevel = logging.INFO
else:
loglevel = logging.WARNING
# if --systemd is given, log to systemd journal
if args.systemd:
logging.basicConfig(level=logging.DEBUG)
log.addHandler(JournalHandler())
else:
logging.basicConfig(level=loglevel)
return log
logger = get_logger()