yuanpei-intelligence / django_utils Goto Github PK
View Code? Open in Web Editor NEWDjango项目工具
Django项目工具
发现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()
需要至少一个参数。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.