diff --git a/gns3server/main.py b/gns3server/main.py index ac6c6b19..ee32440f 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -92,6 +92,7 @@ def parse_arguments(argv, config): "quiet": config.getboolean("quiet", False), "debug": config.getboolean("debug", False), "live": config.getboolean("live", False), + "logfile": config.getboolean("logfile", ""), } parser = argparse.ArgumentParser(description="GNS3 server version {}".format(__version__)) @@ -109,6 +110,7 @@ def parse_arguments(argv, config): parser.add_argument("-d", "--debug", action="store_true", help="show debug logs") parser.add_argument("--live", action="store_true", help="enable code live reload") parser.add_argument("--shell", action="store_true", help="start a shell inside the server (debugging purpose only you need to install ptpython before)") + parser.add_argument("--log", help="send output to logfile instead of console") return parser.parse_args(argv) @@ -141,7 +143,7 @@ def main(): if args.debug: level = logging.DEBUG - user_log = init_logger(level, quiet=args.quiet) + user_log = init_logger(level, logfile=args.log, quiet=args.quiet) user_log.info("GNS3 server version {}".format(__version__)) current_year = datetime.date.today().year user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) diff --git a/gns3server/web/logger.py b/gns3server/web/logger.py index 6c9c1d2b..90865f25 100644 --- a/gns3server/web/logger.py +++ b/gns3server/web/logger.py @@ -78,8 +78,11 @@ class ColouredStreamHandler(logging.StreamHandler): self.handleError(record) -def init_logger(level, quiet=False): - if sys.platform.startswith("win"): +def init_logger(level, logfile=None, quiet=False): + if logfile and len(logfile) > 0: + stream_handler = logging.FileHandler(logfile) + stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{") + elif sys.platform.startswith("win"): stream_handler = logging.StreamHandler(sys.stdout) stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{") else: diff --git a/init/gns3.conf.upstart b/init/gns3.conf.upstart index 6ddccb8a..aadf4c9b 100644 --- a/init/gns3.conf.upstart +++ b/init/gns3.conf.upstart @@ -6,7 +6,7 @@ stop on shutdown script echo $$ > /var/run/gns3.pid - exec start-stop-daemon --start -c gns3 --exec /usr/local/bin/gns3server + exec start-stop-daemon --start -c gns3 --exec /usr/local/bin/gns3server --log /var/log/gns3.log end script pre-start script