Added log to console option for daemon mode

This commit is contained in:
Mark Qvist 2022-05-18 16:33:28 +02:00
parent a6eac0d7ce
commit 7814712118
3 changed files with 24 additions and 7 deletions

View File

@ -46,7 +46,7 @@ class NomadNetworkApp:
if issubclass(e_type, KeyboardInterrupt):
sys.__excepthook__(e_type, e_value, e_traceback)
def __init__(self, configdir = None, rnsconfigdir = None, daemon = False):
def __init__(self, configdir = None, rnsconfigdir = None, daemon = False, force_console = False):
self.version = __version__
self.enable_client = False
self.enable_node = False
@ -59,6 +59,11 @@ class NomadNetworkApp:
else:
self.configdir = configdir
if force_console:
self.force_console_log = True
else:
self.force_console_log = False
if NomadNetworkApp._shared_instance == None:
NomadNetworkApp._shared_instance = self
@ -490,7 +495,7 @@ class NomadNetworkApp:
if RNS.loglevel > 7:
RNS.loglevel = 7
if option == "destination":
if value.lower() == "file":
if value.lower() == "file" and not self.force_console_log:
RNS.logdest = RNS.LOG_FILE
if "logfile" in self.config["logging"]:
self.logfilepath = self.config["logging"]["logfile"]

View File

@ -7,16 +7,22 @@ import argparse
import nomadnet
def program_setup(configdir, rnsconfigdir, daemon):
app = nomadnet.NomadNetworkApp(configdir = configdir, rnsconfigdir = rnsconfigdir, daemon = daemon)
def program_setup(configdir, rnsconfigdir, daemon, console):
app = nomadnet.NomadNetworkApp(
configdir = configdir,
rnsconfigdir = rnsconfigdir,
daemon = daemon,
force_console = console,
)
def main():
try:
parser = argparse.ArgumentParser(description="Nomad Network Client")
parser.add_argument("--config", action="store", default=None, help="path to alternative Nomad Network config directory", type=str)
parser.add_argument("--rnsconfig", action="store", default=None, help="path to alternative Reticulum config directory", type=str)
parser.add_argument("-d", "--daemon", action="store_true", default=False, help="run Nomad Network in daemon mode")
parser.add_argument("-t", "--textui", action="store_true", default=False, help="run Nomad Network in text-UI mode")
parser.add_argument("-d", "--daemon", action="store_true", default=False, help="run Nomad Network in daemon mode")
parser.add_argument("-c", "--console", action="store_true", default=False, help="in daemon mode, log to console instead of file")
parser.add_argument("--version", action="version", version="Nomad Network Client {version}".format(version=__version__))
args = parser.parse_args()
@ -31,15 +37,18 @@ def main():
else:
rnsconfigarg = None
console = False
if args.daemon:
daemon = True
if args.console:
console = True
else:
daemon = False
if args.textui:
daemon = False
program_setup(configarg, rnsconfigarg, daemon)
program_setup(configarg, rnsconfigarg, daemon, console)
except KeyboardInterrupt:
print("")

View File

@ -10,7 +10,10 @@ class NoneUI:
self.app = NomadNetworkApp.get_shared_instance()
self.app.ui = self
if not self.app.force_console_log:
RNS.log("Nomad Network started in daemon mode, all further messages are logged to "+str(self.app.logfilepath), RNS.LOG_INFO, _override_destination=True)
else:
RNS.log("Nomad Network daemon started", RNS.LOG_INFO)
while True:
time.sleep(1)