def add_logging_handler(self, handler): """ Adds a handler """ assert isinstance(handler, logging.Handler), \ f"You must pass a logging.Handler not {type(handler)}" if handler.formatter is None: handler.addFilter(SimTimeContextFilter()) handler.setFormatter(self._uvm_formatter) self.logger.addHandler(handler)
def _gen_log(self, log_name): timenow = datetime.now().strftime("%d_%b_%Y_%Hh_%Mm_%Ss") timenow_wstamp = timenow + str("_") + str(datetime.timestamp(datetime.now())) self.log = SimLog(log_name) self.log.setLevel(logging.DEBUG) self.file_handler = RotatingFileHandler(f"{log_name}_{timenow}.log", maxBytes=(5 * 1024 * 1024), backupCount=2, mode='w') self._symlink_force(f"{log_name}_{timenow}.log",f"latest_{log_name}.log") self.file_handler.setFormatter(SimLogFormatter()) self.log.addHandler(self.file_handler) self.log.addFilter(SimTimeContextFilter()) return timenow_wstamp
def __init__(self): self.logger_holder = uvm_report_object("logger_holder") self.logger_holder.remove_streaming_handler() configdb_handler = logging.StreamHandler() configdb_handler.addFilter(SimTimeContextFilter()) # Don't let the handler interfere with logger level configdb_handler.setLevel(logging.NOTSET) # Make log messages look like UVM messages configdb_formatter = SimColourLogFormatter() configdb_handler.setFormatter(configdb_formatter) self.logger_holder.add_logging_handler(configdb_handler) self.logger_holder.logger.propagate = False self._path_dict = {} self.is_tracing = False self._cond_dict = {}
def __init__(self, name): super().__init__(name) uvm_root_logger = logging.getLogger('uvm') # Every object gets its own logger logger_name = self.get_full_name() + str(id(self)) self.logger = uvm_root_logger.getChild(logger_name) self.logger.setLevel( level=uvm_report_object.get_default_logging_level()) # We are not sending log messages up the hierarchy self.logger.propagate = False self._streaming_handler = logging.StreamHandler(sys.stdout) self._streaming_handler.addFilter(SimTimeContextFilter()) # Don't let the handler interfere with logger level self._streaming_handler.setLevel(logging.NOTSET) # Make log messages look like UVM messages self._uvm_formatter = PyuvmFormatter(self.get_full_name()) self.add_logging_handler(self._streaming_handler)
def __init__(self, signals, debug=False, slots=0, width=0): level = logging.DEBUG if debug else logging.WARNING self.log = SimLog("afifo.log") file_handler = RotatingFileHandler("sim.log", maxBytes=(5 * 1024 * 1024), backupCount=2, mode='w') file_handler.setFormatter(SimColourLogFormatter()) self.log.addHandler(file_handler) self.log.addFilter(SimTimeContextFilter()) self.log.setLevel(level) self.log.info("SEED ======> %s", str(cocotb.RANDOM_SEED)) self.clk_wr = signals.clk_wr self.valid_wr = signals.wr_en_i self.data_wr = signals.wr_data_i self.ready_wr = signals.wr_full_o self.clk_rd = signals.clk_rd self.valid_rd = signals.rd_empty_o self.data_rd = signals.rd_data_o self.ready_rd = signals.rd_en_i self.valid_wr <= 0 self.ready_rd <= 0 self.log.setLevel(level)
import abc import collections import inspect import itertools import logging import pprint from typing import List, Callable, Dict from cocotb.log import SimLogFormatter, SimColourLogFormatter, SimLog, SimBaseLog, SimTimeContextFilter, want_color_output # Ad hoc logging root = logging.getLogger() fh = logging.FileHandler(__name__, 'w+') fh.addFilter(SimTimeContextFilter()) fh.setFormatter( SimColourLogFormatter() if want_color_output() else SimLogFormatter()) def log(name, level, id=None): """ `cocotb.SimLog` with levels.""" new = SimLog(name, id) new.setLevel(level) return new class CroppingPrettyPrinter(pprint.PrettyPrinter): """From https://stackoverflow.com/questions/23567628/how-to-check-if-len-is-valid""" def __init__(self, *args, **kwargs): self.maxlist = kwargs.pop('maxlist', 10)