mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-19 21:07:57 +00:00
Add --log options for daemon support
This commit is contained in:
parent
fc289fd868
commit
9c549b175f
@ -92,6 +92,7 @@ def parse_arguments(argv, config):
|
|||||||
"quiet": config.getboolean("quiet", False),
|
"quiet": config.getboolean("quiet", False),
|
||||||
"debug": config.getboolean("debug", False),
|
"debug": config.getboolean("debug", False),
|
||||||
"live": config.getboolean("live", False),
|
"live": config.getboolean("live", False),
|
||||||
|
"logfile": config.getboolean("logfile", ""),
|
||||||
}
|
}
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="GNS3 server version {}".format(__version__))
|
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("-d", "--debug", action="store_true", help="show debug logs")
|
||||||
parser.add_argument("--live", action="store_true", help="enable code live reload")
|
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("--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)
|
return parser.parse_args(argv)
|
||||||
|
|
||||||
@ -141,7 +143,7 @@ def main():
|
|||||||
if args.debug:
|
if args.debug:
|
||||||
level = logging.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__))
|
user_log.info("GNS3 server version {}".format(__version__))
|
||||||
current_year = datetime.date.today().year
|
current_year = datetime.date.today().year
|
||||||
user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
|
user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
|
||||||
|
@ -78,8 +78,11 @@ class ColouredStreamHandler(logging.StreamHandler):
|
|||||||
self.handleError(record)
|
self.handleError(record)
|
||||||
|
|
||||||
|
|
||||||
def init_logger(level, quiet=False):
|
def init_logger(level, logfile=None, quiet=False):
|
||||||
if sys.platform.startswith("win"):
|
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 = logging.StreamHandler(sys.stdout)
|
||||||
stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{")
|
stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{")
|
||||||
else:
|
else:
|
||||||
|
@ -6,7 +6,7 @@ stop on shutdown
|
|||||||
|
|
||||||
script
|
script
|
||||||
echo $$ > /var/run/gns3.pid
|
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
|
end script
|
||||||
|
|
||||||
pre-start script
|
pre-start script
|
||||||
|
Loading…
Reference in New Issue
Block a user