def format(self, record: logging.LogRecord): # colorized logs try: func = self.__colors[record.levelname] except KeyError: func = self.__standard_print # remove .py extension in filename record.filename = record.filename[:-3] # add "..." on too long filenames if self.__limit_filename_size is not None and len(record.filename) > self.__limit_filename_size: record.filename = record.filename[:(self.__limit_filename_size-3)] + '...' result = super().format(record) return func(result)
def filter(self, record: logging.LogRecord) -> bool: """ Modify the stack info if necessary. :param record: log record :return: true if record should be logged (always) """ tags = "tango-device:" + TangoFilter.device_name transaction_id = TangoFilter.transaction_id.get() if transaction_id: tags += "," + transaction_id record.tags = tags level = record.levelno if level not in _PYTHON_TO_TANGO: record.levelno = to_python_level(tango.LogLevel(level)) # If the record originates from this module, insert the # right frame info. if record.pathname == __file__: thread = threading.current_thread() # The thread should be in the dictionary, but may not be if the # module has been reloaded e.g. by unit test. if thread in TangoFilter.log_man.frames: frame = TangoFilter.log_man.frames[thread] record.funcName = frame.function record.filename = pathlib.Path(frame.filename).name record.lineno = frame.lineno return True
def format(self, record: logging.LogRecord) -> str: # If the record originates from this module, insert the right frame info. if record.pathname == __file__: frame = self.log_man.frames[threading.current_thread()] record.funcName = frame.function record.filename = pathlib.Path(frame.filename).name record.lineno = frame.lineno return super().format(record)
def format(self, record: logging.LogRecord) -> str: # If the record originates from this module, insert the right frame info. if record.pathname == __file__: thread = threading.current_thread() # The thread should be in the dictionary, but may not be if the # module has been reloaded e.g. by unit test. if thread in self.log_man.frames: frame = self.log_man.frames[thread] record.funcName = frame.function record.filename = pathlib.Path(frame.filename).name record.lineno = frame.lineno return super().format(record)
def filter(self, record: logging.LogRecord) -> bool: if record.pathname == __file__: frames = inspect.stack() frame = None for frame in frames: if self.ignore(frame): continue if self.match(frame): break record.funcName = frame.function record.filename = pathlib.Path(frame.filename).name record.lineno = frame.lineno return True
def format(self, record: logging.LogRecord) -> str: record = copy.copy(record) record.levelname = getattr( self._scheme, record.levelname.lower()).colored(record.levelname) record.levelno = getattr(self._scheme, logging.getLevelName( record.levelno).lower()).colored( record.levelno) record.name = self._scheme.name.colored(record.name) record.process = self._scheme.process.colored(record.process) record.processName = self._scheme.process.colored(record.processName) record.thread = self._scheme.thread.colored(record.thread) record.threadName = self._scheme.thread.colored(record.threadName) record.lineno = self._scheme.lineno.colored(record.lineno) record.pathname = self._scheme.pathname.colored(record.pathname) record.funcName = self._scheme.funcname.colored(record.funcName) record.filename = self._scheme.filename.colored(record.filename) return super(ColoredFormatter, self).format(record)
def format(self, record: logging.LogRecord) -> str: """ :param record: :return: """ """ Attribute name Format Description args You shouldn’t need to format this yourself. The tuple of arguments merged into msg to produce message, or a dict whose values are used for the merge (when there is only one argument, and it is a dictionary). asctime %(asctime)s Human-readable time when the LogRecord was created. By default this is of the form ‘2003-07-08 16:49:45,896’ (the numbers after the comma are millisecond portion of the time). created %(created)f Time when the LogRecord was created (as returned by time.time()). exc_info You shouldn’t need to format this yourself. Exception tuple (à la sys.exc_info) or, if no exception has occurred, None. filename %(filename)s Filename portion of pathname. funcName %(funcName)s Name of function containing the logging call. levelname %(levelname)s Text logging level for the message ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'). levelno %(levelno)s Numeric logging level for the message (DEBUG, INFO, WARNING, ERROR, CRITICAL). lineno %(lineno)d Source line number where the logging call was issued (if available). module %(module)s Module (name portion of filename). msecs %(msecs)d Millisecond portion of the time when the LogRecord was created. message %(message)s The logged message, computed as msg % args. This is set when Formatter.format() is invoked. msg You shouldn’t need to format this yourself. The format string passed in the original logging call. Merged with args to produce message, or an arbitrary object (see Using arbitrary objects as messages). name %(name)s Name of the config_logger used to log the call. pathname %(pathname)s Full pathname of the source file where the logging call was issued (if available). process %(process)d Process ID (if available). processName %(processName)s Process name (if available). relativeCreated %(relativeCreated)d Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded. stack_info You shouldn’t need to format this yourself. Stack frame information (where available) from the bottom of the stack in the current thread, up to and including the stack frame of the logging call which resulted in the creation of this record. thread %(thread)d Thread ID (if available). threadName %(threadName)s Thread name (if available). [service.randomtrailers.backend:DiscoverTmdbMovies:process_page] [service.randomtrailers.backend:FolderMovieData:add_to_discovered_trailers TRACE_DISCOVERY] """ # threadName Constants.CURRENT_ADDON_SHORT_NAME funcName:lineno # [threadName name funcName:lineno] text = '' try: start_file = record.__dict__.get('start_file', None) try: pathname, lineno, func = start_file except ValueError: pathname, lineno, func = "(unknown file)", 0, "(unknown function)" record.pathname = pathname try: record.filename = os.path.basename(pathname) record.module = os.path.splitext(record.filename)[0] except (TypeError, ValueError, AttributeError): record.filename = pathname record.module = "Unknown module" record.lineno = lineno record.funcName = func suffix = super().format(record) passed_traces = record.__dict__.get('trace_string', None) if passed_traces is None: if type(self).INCLUDE_THREAD_INFO: prefix = '[Thread {!s} {!s}.{!s}:{!s}:{!s}]'.format( record.threadName, record.name, record.funcName, record.lineno, record.levelname) else: prefix = '[{!s}.{!s}:{!s}]'.format(record.name, record.funcName, record.lineno) else: if type(self).INCLUDE_THREAD_INFO: prefix = '[Thread {!s} {!s}.{!s}:{!s}:{!s} Trace:{!s}]'.format( record.threadName, record.name, record.funcName, record.lineno, record.levelname, passed_traces) else: prefix = '[{!s}.{!s}:{!s}:{!s} Trace:{!s}]'.format( record.name, record.funcName, record.lineno, record.levelname, passed_traces) text = '{} {}'.format(prefix, suffix) except Exception as e: pass return text