Skip to content

Commit

Permalink
Log reporting now includes some of console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
Kataiser committed Jul 20, 2018
1 parent 2458248 commit f74665b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,18 @@ def current_log():
def report_log():
info(f"Reporting {filename} ({os.stat(filename).st_size} bytes) to Sentry")
if not dev:
with open(filename) as current_log_file:
client.captureMessage(f"{filename} {current_log_file.read()}")
if not console_log_path:
client.captureMessage(f"{filename}\n{read_truncated_file(filename)}")
else:
client.captureMessage(f"{filename}\n{read_truncated_file(filename)}\n{read_truncated_file(console_log_path)}")


def read_truncated_file(path):
with open(path, 'r', errors='replace') as file:
file_size = os.stat(path).st_size
if file_size > 410000:
file.seek(file_size - 400000)
return file.read()


try:
Expand All @@ -73,6 +83,7 @@ def report_log():
user_pc_name = socket.gethostbyaddr(socket.gethostname())[0]
filename = os.path.join('logs', '{}-{}-{}-{}.log'.format(user_pc_name, user_identifier, '{tf2rpvnum}', main_hash[:8]))
dev = False
console_log_path = None

# sentry.io, for error reporting
client = Client(dsn='https://de781ce2454f458eafab1992630bc100:[email protected]/1245944',
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def main():
# console.log is a log of tf2's console (duh), only exists if tf2 has -condebug (see the bottom of config_files)
consolelog_filename = os.path.join(tf2_location, 'tf', 'console.log')
log.debug(f"Looking for console.log at {consolelog_filename}")
log.console_log_path = consolelog_filename
with open(consolelog_filename, 'r', errors='replace') as consolelog_file:
consolelog_file_size = os.stat(consolelog_filename).st_size
log.debug(f"console.log: {consolelog_file_size} bytes, {len(consolelog_file.readlines())} lines")
Expand Down
4 changes: 2 additions & 2 deletions updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def check(current_version, timeout):
r = http.request('GET', 'https://api.github.com/repos/Kataiser/tf2-rich-presence/releases/latest', timeout=timeout)
except urllib3.exceptions.MaxRetryError:
log.error(f"Update check timed out")
line1 = "\nCouldn't connect to GitHub to check for updates (timed out after {} seconds).\n".format(timeout)
line1 = "Couldn't connect to GitHub to check for updates (timed out after {} seconds).\n".format(timeout)
line2 = "To check for updates yourself, go to https://github.com/Kataiser/tf2-rich-presence/releases\n"
line3 = "(you are currently running {}).\n".format(current_version)
print(f"{line1}{line2}{line3}")
Expand All @@ -24,7 +24,7 @@ def check(current_version, timeout):
if current_version != newest_version: # out of date
log.error(f"Out of date, newest version is {newest_version}")
downloads_url = response['html_url']
print(f"\nThis version ({current_version}) is out of date (newest version is {newest_version}).\nGet the update at {downloads_url}\n")
print(f"This version ({current_version}) is out of date (newest version is {newest_version}).\nGet the update at {downloads_url}\n")


if __name__ == '__main__':
Expand Down

0 comments on commit f74665b

Please sign in to comment.