diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index 62b4865..69af68e 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -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"] diff --git a/nomadnet/nomadnet.py b/nomadnet/nomadnet.py index c48151d..cb8591f 100644 --- a/nomadnet/nomadnet.py +++ b/nomadnet/nomadnet.py @@ -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("") diff --git a/nomadnet/ui/NoneUI.py b/nomadnet/ui/NoneUI.py index c3aee59..40a58cc 100644 --- a/nomadnet/ui/NoneUI.py +++ b/nomadnet/ui/NoneUI.py @@ -10,7 +10,10 @@ class NoneUI: self.app = NomadNetworkApp.get_shared_instance() self.app.ui = self - RNS.log("Nomad Network started in daemon mode, all further messages are logged to "+str(self.app.logfilepath), RNS.LOG_INFO, _override_destination=True) + 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) \ No newline at end of file