diff --git a/wakatime/logger.py b/wakatime/logger.py index 13d9454..78b38ee 100644 --- a/wakatime/logger.py +++ b/wakatime/logger.py @@ -73,7 +73,14 @@ class JsonFormatter(logging.Formatter): def traceback_formatter(*args, **kwargs): - logging.getLogger('WakaTime').error(traceback.format_exc()) + if 'level' in kwargs and (kwargs['level'].lower() == 'warn' or kwargs['level'].lower() == 'warning'): + logging.getLogger('WakaTime').warning(traceback.format_exc()) + elif 'level' in kwargs and kwargs['level'].lower() == 'info': + logging.getLogger('WakaTime').info(traceback.format_exc()) + elif 'level' in kwargs and kwargs['level'].lower() == 'debug': + logging.getLogger('WakaTime').debug(traceback.format_exc()) + else: + logging.getLogger('WakaTime').error(traceback.format_exc()) def set_log_level(logger, args): diff --git a/wakatime/projects/git.py b/wakatime/projects/git.py index 091f5c9..fb4f2ac 100644 --- a/wakatime/projects/git.py +++ b/wakatime/projects/git.py @@ -44,9 +44,9 @@ class Git(BaseProject): with open(head, 'r', encoding=sys.getfilesystemencoding()) as fh: return u(fh.readline().strip().rsplit('/', 1)[-1]) except: - log.traceback() + log.traceback('warn') except IOError: # pragma: nocover - log.traceback() + log.traceback('warn') return None def _project_base(self): diff --git a/wakatime/projects/mercurial.py b/wakatime/projects/mercurial.py index 399edd5..4369ddb 100644 --- a/wakatime/projects/mercurial.py +++ b/wakatime/projects/mercurial.py @@ -42,9 +42,9 @@ class Mercurial(BaseProject): with open(branch_file, 'r', encoding=sys.getfilesystemencoding()) as fh: return u(fh.readline().strip().rsplit('/', 1)[-1]) except: - log.traceback() + log.traceback('warn') except IOError: # pragma: nocover - log.traceback() + log.traceback('warn') return u('default') def _find_hg_config_dir(self, path): diff --git a/wakatime/projects/wakatime_project_file.py b/wakatime/projects/wakatime_project_file.py index 76fc7d2..8ec4ccf 100644 --- a/wakatime/projects/wakatime_project_file.py +++ b/wakatime/projects/wakatime_project_file.py @@ -41,9 +41,9 @@ class WakaTimeProjectFile(BaseProject): self._project_name = u(fh.readline().strip()) self._project_branch = u(fh.readline().strip()) except: - log.traceback() + log.traceback('warn') except IOError: # pragma: nocover - log.traceback() + log.traceback('warn') return True return False diff --git a/wakatime/session_cache.py b/wakatime/session_cache.py index 8804748..e20beae 100644 --- a/wakatime/session_cache.py +++ b/wakatime/session_cache.py @@ -57,7 +57,7 @@ class SessionCache(object): conn.commit() conn.close() except: # pragma: nocover - log.traceback() + log.traceback('debug') def get(self): @@ -72,7 +72,7 @@ class SessionCache(object): try: conn, c = self.connect() except: - log.traceback() + log.traceback('debug') return requests.session() session = None @@ -83,12 +83,12 @@ class SessionCache(object): if row is not None: session = pickle.loads(row[0]) except: # pragma: nocover - log.traceback() + log.traceback('debug') try: conn.close() except: # pragma: nocover - log.traceback() + log.traceback('debug') return session if session is not None else requests.session() @@ -105,4 +105,4 @@ class SessionCache(object): conn.commit() conn.close() except: - log.traceback() + log.traceback('debug') diff --git a/wakatime/stats.py b/wakatime/stats.py index 2606fa4..81fb283 100644 --- a/wakatime/stats.py +++ b/wakatime/stats.py @@ -191,5 +191,5 @@ def get_file_contents(file_name): with open(file_name, 'r', encoding=sys.getfilesystemencoding()) as fh: text = fh.read(512000) except: - log.traceback() + log.traceback('debug') return text