mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2025-01-14 18:52:08 +05:30
added --systemd and --verbose arguments
When run without --systemd, naxalnet will log to stderr. Otherwise, it will log to systemd journal. log.py is no longer needed.
This commit is contained in:
parent
a3e9b45050
commit
2d9aee4d3a
@ -27,7 +27,7 @@ RestartSec=2sec
|
|||||||
# naxalnet cannot start a mesh network but exits without errors.
|
# naxalnet cannot start a mesh network but exits without errors.
|
||||||
# So, we give a 2s delay.
|
# So, we give a 2s delay.
|
||||||
ExecStartPre=/usr/bin/sleep 2
|
ExecStartPre=/usr/bin/sleep 2
|
||||||
ExecStart=/usr/bin/naxalnet
|
ExecStart=/usr/bin/naxalnet --systemd
|
||||||
# Reload systemd-networkd after naxalnet exits
|
# Reload systemd-networkd after naxalnet exits
|
||||||
ExecStartPost=/usr/bin/networkctl reload
|
ExecStartPost=/usr/bin/networkctl reload
|
||||||
# Delete all files starting with mesh.* in /run/systemd/network
|
# Delete all files starting with mesh.* in /run/systemd/network
|
||||||
|
@ -36,4 +36,4 @@ See README.md for documentation.
|
|||||||
#
|
#
|
||||||
# In case you forgot to change the version, skip the number
|
# In case you forgot to change the version, skip the number
|
||||||
# and put the next number in the next commit.
|
# and put the next number in the next commit.
|
||||||
__version__ = "0.3.0a2.dev1"
|
__version__ = "0.3.0a2.dev2"
|
||||||
|
@ -139,6 +139,13 @@ def parse_args() -> Namespace:
|
|||||||
help="volatile directory where configuration files of systemd-networkd should be copied",
|
help="volatile directory where configuration files of systemd-networkd should be copied",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--systemd",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="send log messages to systemd journal",
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--version",
|
"--version",
|
||||||
default=False,
|
default=False,
|
||||||
@ -146,5 +153,9 @@ def parse_args() -> Namespace:
|
|||||||
help="prints the version and exit",
|
help="prints the version and exit",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-v", "--verbose", action="count", default=0, help="increase output verbosity"
|
||||||
|
)
|
||||||
|
|
||||||
# logger.debug("Parsing arguments")
|
# logger.debug("Parsing arguments")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
@ -58,8 +58,11 @@ and what they mean:
|
|||||||
- node: a machine that runs naxalnet and is therefore
|
- node: a machine that runs naxalnet and is therefore
|
||||||
connected to the mesh.
|
connected to the mesh.
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
from dasbus.connection import SystemMessageBus
|
from dasbus.connection import SystemMessageBus
|
||||||
from naxalnet.log import logger
|
|
||||||
|
# from naxalnet.log import logger
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
IWD_BUS = "net.connman.iwd"
|
IWD_BUS = "net.connman.iwd"
|
||||||
IWD_ROOT_PATH = "/"
|
IWD_ROOT_PATH = "/"
|
||||||
|
@ -10,7 +10,22 @@ to the systemd journal
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from systemd import journal
|
from systemd import journal
|
||||||
|
from naxalnet.config import parse_args
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
def get_logger():
|
||||||
logger.addHandler(journal.JournalHandler())
|
"""returns the logger object for logging"""
|
||||||
|
|
||||||
|
args = parse_args()
|
||||||
|
if args.systemd:
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
logger.addHandler(journal.JournalHandler())
|
||||||
|
else:
|
||||||
|
# logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
|
logger = get_logger()
|
||||||
|
@ -28,13 +28,18 @@ When run from the commandline, the function here_be_dragons() is called.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copy
|
from shutil import copy
|
||||||
from dasbus.error import DBusError
|
from dasbus.error import DBusError
|
||||||
|
from systemd import journal
|
||||||
from naxalnet import __version__
|
from naxalnet import __version__
|
||||||
from naxalnet.iwd import Adapter, Device, IWD
|
from naxalnet.iwd import Adapter, Device, IWD
|
||||||
from naxalnet.config import parse_args
|
from naxalnet.config import parse_args
|
||||||
from naxalnet.log import logger
|
|
||||||
|
# from naxalnet.log import logger
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def copy_files(args):
|
def copy_files(args):
|
||||||
@ -144,6 +149,21 @@ def here_be_dragons():
|
|||||||
"""
|
"""
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
|
# --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:
|
||||||
|
logger.setLevel(level=logging.DEBUG)
|
||||||
|
logger.addHandler(journal.JournalHandler())
|
||||||
|
else:
|
||||||
|
logging.basicConfig(level=loglevel)
|
||||||
|
|
||||||
if args.print_wifi:
|
if args.print_wifi:
|
||||||
print_wifi(args)
|
print_wifi(args)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user