Giter VIP home page Giter VIP logo

django_utils's People

Watchers

rickyds97 avatar

django_utils's Issues

`utils.log.logger.Logger.getLogger()`在初始化新的logger时会报错

发现getLogger()的在setup == True时,会调用logger.setup(name),然后回调用add_default_handler

    @classmethod
    def getLogger(cls, name: str, setup: bool = True):
        if name in _loggers:
            return cast(cls, _loggers[name])
        _logger_class  = logging.getLoggerClass()
        logging.setLoggerClass(cls)
        logger = cast(cls, logging.getLogger(name))
        logging.setLoggerClass(_logger_class)
        if setup:
            logger.setup(name)
        _loggers[name] = logger
        return logger

    def setup(self, name: str, handle: bool = True) -> None:
        self.setupConfig()
        if handle: self.add_default_handler(name)

    def setupConfig(self) -> None:
        from django.conf import settings
        self.debug_mode = settings.DEBUG
        self.format = '{asctime} [{levelname}] {message}'
        self.format_style = '{'
        self.stack_level = 8
        self.setLevel(logging.INFO)

    def add_default_handler(self, name: str, *paths: str, format: str = None) -> None:
        base_dir = os.path.join(*paths)
        os.makedirs(base_dir, exist_ok=True)
        file_path = os.path.join(base_dir, name + '.log')
        handler = logging.FileHandler(file_path, encoding='UTF8', mode='a')
        formatter = logging.Formatter(format or self.format, style=self.format_style)
        handler.setFormatter(formatter)
        self.addHandler(handler)

但是此时paths是空的,导致在os.path.join(*paths)一行报错,因为os.path.join()需要至少一个参数。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.