diff --git a/pagure/lib/tasks_services.py b/pagure/lib/tasks_services.py index 4806107..267b82a 100644 --- a/pagure/lib/tasks_services.py +++ b/pagure/lib/tasks_services.py @@ -11,13 +11,11 @@ import datetime import hashlib import hmac -import inspect import json import logging import os import os.path import time -import traceback import uuid import requests @@ -30,6 +28,8 @@ from sqlalchemy.exc import SQLAlchemyError import pagure.lib from pagure.config import config as pagure_config from pagure.lib.tasks import set_status +from pagure.mail_logging import format_callstack + # logging.config.dictConfig(pagure_config.get('LOGGING') or {'version': 1}) _log = logging.getLogger(__name__) @@ -198,25 +198,6 @@ def log_commit_send_notifications( session.close() -def format_callstack(): - """ Format the callstack to find out the stack trace. """ - ind = 0 - for ind, frame in enumerate(f[0] for f in inspect.stack()): - if '__name__' not in frame.f_globals: - continue - modname = frame.f_globals['__name__'].split('.')[0] - if modname != "logging": - break - - def _format_frame(frame): - """ Format the frame. """ - return ' File "%s", line %i in %s\n %s' % (frame) - - stack = traceback.extract_stack() - stack = stack[:-ind] - return "\n".join([_format_frame(frame) for frame in stack]) - - def get_files_to_load(title, new_commits_list, abspath): _log.info('%s: Retrieve the list of files changed' % title) diff --git a/pagure/mail_logging.py b/pagure/mail_logging.py index c1b7f95..5f751f7 100644 --- a/pagure/mail_logging.py +++ b/pagure/mail_logging.py @@ -41,6 +41,25 @@ except (OSError, ImportError): # pragma: no cover pass +def format_callstack(): + """ Format the callstack to find out the stack trace. """ + ind = 0 + for ind, frame in enumerate(f[0] for f in inspect.stack()): + if '__name__' not in frame.f_globals: + continue + modname = frame.f_globals['__name__'].split('.')[0] + if modname != "logging": + break + + def _format_frame(frame): + """ Format the frame. """ + return ' File "%s", line %i in %s\n %s' % (frame) + + stack = traceback.extract_stack() + stack = stack[:-ind] + return "\n".join([_format_frame(frame) for frame in stack]) + + class ContextInjector(logging.Filter): # pragma: no cover """ Logging filter that adds context to log records. @@ -86,7 +105,7 @@ class ContextInjector(logging.Filter): # pragma: no cover cmd_line = cmd_line() record.command_line = " ".join(cmd_line) - record.callstack = self.format_callstack() + record.callstack = format_callstack() try: record.url = getattr(flask.request, 'url', '-') @@ -113,25 +132,6 @@ class ContextInjector(logging.Filter): # pragma: no cover return True @staticmethod - def format_callstack(): - """ Format the callstack to find out the stack trace. """ - ind = 0 - for ind, frame in enumerate(f[0] for f in inspect.stack()): - if '__name__' not in frame.f_globals: - continue - modname = frame.f_globals['__name__'].split('.')[0] - if modname != "logging": - break - - def _format_frame(frame): - """ Format the frame. """ - return ' File "%s", line %i in %s\n %s' % (frame) - - stack = traceback.extract_stack() - stack = stack[:-ind] - return "\n".join([_format_frame(frame) for frame in stack]) - - @staticmethod def get_current_process(): """ Return the current process (PID). """ if not psutil: