2021-09-20 12:28:59 +05:30
|
|
|
# This file is part of naxalnet.
|
|
|
|
# Copyright (C) 2021 The naxalnet Authors
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2021-09-07 18:45:11 +05:30
|
|
|
"""
|
|
|
|
log.py
|
|
|
|
------
|
|
|
|
|
2021-10-02 14:13:53 +05:30
|
|
|
Initialise the logger for other submodules to import. Do not import any
|
|
|
|
submodules here other than naxallnet.config, which is needed to set the
|
|
|
|
loglevel and to add the systemd journal handler
|
2021-09-07 18:45:11 +05:30
|
|
|
"""
|
|
|
|
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()
|