Skip to content

Commit

Permalink
Fixes problems non-existent paths for logfiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed May 31, 2014
1 parent fb84028 commit 179e78d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 17 additions & 9 deletions gns3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,26 @@ def exceptionHook(exception, value, tb):
app.setApplicationName("GNS3")
app.setApplicationVersion(__version__)

# save client logging info to a file
logfile = os.path.join(os.path.dirname(QtCore.QSettings().fileName()), "GNS3_client.log")
try:
logger = logging.getLogger("gns3")
try:
os.makedirs(os.path.dirname(QtCore.QSettings().fileName()))
except FileExistsError:
pass
handler = logging.FileHandler(logfile, "w")
handler.setLevel(logging.INFO)
formatter = logging.Formatter("[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d] %(message)s",
datefmt="%y%m%d %H:%M:%S")
handler.setFormatter(formatter)
logger.addHandler(handler)
except OSError as e:
log.warn("could not log to {}: {}".format(logfile, e))

# update the exception file path to have it in the same directory as the settings file.
exception_file_path = os.path.join(os.path.dirname(QtCore.QSettings().fileName()), exception_file_path)

# save client logging info to a file
logger = logging.getLogger("gns3")
handler = logging.FileHandler(os.path.join(os.path.dirname(QtCore.QSettings().fileName()), "GNS3_client.log"), "w")
handler.setLevel(logging.INFO)
formatter = logging.Formatter("[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d] %(message)s",
datefmt="%y%m%d %H:%M:%S")
handler.setFormatter(formatter)
logger.addHandler(handler)

mainwindow = MainWindow.instance()
mainwindow.show()
exit_code = app.exec_()
Expand Down
4 changes: 2 additions & 2 deletions gns3/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def startLocalServer(self, path, host, port):
os.remove(logpath)
except FileNotFoundError:
pass
except OSError:
log.warn("could not delete {}".format(logpath))
except OSError as e:
log.warn("could not delete server log file {}: {}".format(logpath, e))

command = '"{executable}" --host={host} --port={port} --log_file_prefix={logpath} ' \
'--log_file_num_backups=0 --log_to_stderr'.format(executable=path,
Expand Down

0 comments on commit 179e78d

Please sign in to comment.