forked from uncloud/uncloud
- Better error reporting.
- Flask now uses application's logger instead of its own. - ucloud file scanner refactored.
This commit is contained in:
parent
eea6c1568e
commit
972bb5a920
14 changed files with 157 additions and 154 deletions
|
|
@ -6,44 +6,23 @@ import importlib
|
|||
import multiprocessing as mp
|
||||
import sys
|
||||
|
||||
import colorama
|
||||
|
||||
from logging.handlers import SysLogHandler
|
||||
|
||||
from ucloud.configure.main import configure_parser
|
||||
from ucloud.common.logging import NoTracebackStreamHandler
|
||||
|
||||
|
||||
def exception_hook(exc_type, exc_value, exc_traceback):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.error(
|
||||
'Uncaught exception',
|
||||
exc_info=(exc_type, exc_value, exc_traceback)
|
||||
)
|
||||
# print('Error: ', end='')
|
||||
# print(exc_type, exc_value, exc_traceback)
|
||||
|
||||
|
||||
class NoTracebackStreamHandler(logging.StreamHandler):
|
||||
def handle(self, record):
|
||||
info, cache = record.exc_info, record.exc_text
|
||||
record.exc_info, record.exc_text = None, None
|
||||
|
||||
if record.levelname == 'WARNING':
|
||||
color = colorama.Fore.YELLOW
|
||||
elif record.levelname == 'ERROR':
|
||||
color = colorama.Fore.LIGHTRED_EX
|
||||
else:
|
||||
color = colorama.Fore.RED
|
||||
try:
|
||||
print(color)
|
||||
super().handle(record)
|
||||
finally:
|
||||
record.exc_info = info
|
||||
record.exc_text = cache
|
||||
print(colorama.Style.RESET_ALL)
|
||||
sys.excepthook = exception_hook
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.excepthook = exception_hook
|
||||
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
subparsers = arg_parser.add_subparsers(dest="command")
|
||||
|
||||
|
|
@ -68,7 +47,7 @@ if __name__ == '__main__':
|
|||
arg_parser.print_help()
|
||||
else:
|
||||
# Setting up root logger
|
||||
logger = logging.getLogger('ucloud')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
syslog_handler = SysLogHandler(address='/dev/log')
|
||||
syslog_handler.setLevel(logging.DEBUG)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue