|
@@ -1,10 +1,7 @@
|
|
|
-
|
|
|
import logging
|
|
|
import os
|
|
|
import time
|
|
|
-
|
|
|
-
|
|
|
-class logger(object):
|
|
|
+class logger:
|
|
|
"""
|
|
|
终端打印不同颜色的日志,在pycharm中如果强行规定了日志的颜色, 这个方法不会起作用, 但是
|
|
|
对于终端,这个方法是可以打印不同颜色的日志的。
|
|
@@ -57,11 +54,17 @@ class logger(object):
|
|
|
|
|
|
def fontColor(self, color):
|
|
|
# 不同的日志输出不同的颜色
|
|
|
- formatter = logging.Formatter(color % '[%(asctime)s] - [%(levelname)s] - %(message)s')
|
|
|
+ formatter = logging.Formatter(color % '[%(asctime)s] - [%(name)s]- [%(levelname)s] - %(message)s')
|
|
|
self.ch.setFormatter(formatter)
|
|
|
self.logger.addHandler(self.ch)
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
- rootpath = os.path.dirname(os.path.dirname(__file__))
|
|
|
- print(rootpath)
|
|
|
+ # rootpath = os.path.dirname(os.path.dirname(__file__))
|
|
|
+ # print(rootpath)
|
|
|
+ log=logger()
|
|
|
+ log.info('aaa')
|
|
|
+ log.debug('2222')
|