mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-02 00:18:17 +00:00
we'll need to replace python logging in our container for performance
This commit is contained in:
1 parent
a3cabf6779
commit
ecca8ff17c
1 file changed
+87
@@ -0,0 +1,87 @@
|
||||
"""
|
||||
Python's default logger may be causing lock contention issues.
|
||||
|
||||
We've seen tremendous slowdown in so-vits-svc, and the logging crate
|
||||
seems to be one of the big contributors.
|
||||
|
||||
Other projects are seeing this as well:
|
||||
https://github.com/kubernetes-client/python/issues/1867
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
# From the original crate
|
||||
CRITICAL = 50
|
||||
FATAL = CRITICAL
|
||||
ERROR = 40
|
||||
WARNING = 30
|
||||
WARN = WARNING
|
||||
INFO = 20
|
||||
DEBUG = 10
|
||||
NOTSET = 0
|
||||
|
||||
# From the original crate
|
||||
_levelToName = {
|
||||
CRITICAL: 'CRITICAL',
|
||||
ERROR: 'ERROR',
|
||||
WARNING: 'WARNING',
|
||||
INFO: 'INFO',
|
||||
DEBUG: 'DEBUG',
|
||||
NOTSET: 'NOTSET',
|
||||
}
|
||||
_nameToLevel = {
|
||||
'CRITICAL': CRITICAL,
|
||||
'FATAL': FATAL,
|
||||
'ERROR': ERROR,
|
||||
'WARN': WARNING,
|
||||
'WARNING': WARNING,
|
||||
'INFO': INFO,
|
||||
'DEBUG': DEBUG,
|
||||
'NOTSET': NOTSET,
|
||||
}
|
||||
|
||||
|
||||
def _get_log_level():
|
||||
level = os.getenv("PYTHON_LOG_LEVEL")
|
||||
if not level or type(level) is not str:
|
||||
return WARN
|
||||
level = level.strip().upper()
|
||||
if level in _nameToLevel:
|
||||
return _nameToLevel[level]
|
||||
return WARN
|
||||
|
||||
|
||||
class Logger:
|
||||
def __init__(self):
|
||||
self.level = _get_log_level()
|
||||
self.handlers = [] # We don't care about this complexity
|
||||
self.flush = True
|
||||
pass
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
def setLevel(self, level):
|
||||
self.level = level
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
def addHandler(self, *args):
|
||||
pass
|
||||
|
||||
def warning(self, *args):
|
||||
print(args, flush=self.flush)
|
||||
|
||||
def warn(self, *args):
|
||||
print(args, flush=self.flush)
|
||||
|
||||
def info(self, *args):
|
||||
print(args, flush=self.flush)
|
||||
|
||||
def debug(self, *args):
|
||||
print(args, flush=self.flush)
|
||||
|
||||
|
||||
LOGGER = Logger()
|
||||
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
def getLogger(*args):
|
||||
return LOGGER
|
||||
Reference in new issue
Block a user