diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index f6261a8..6743fc2 100755 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -16,7 +16,7 @@ from aiohttp_session.redis_storage import RedisStorage from appPublic.jsonConfig import getConfig from appPublic.rsawrap import RSA -from appPublic.app_logger import AppLogger +from appPublic.log import info, debug, warning, error, critical, exception def get_client_ip(obj, request): ip = request.headers.get('X-Forwarded-For') @@ -58,9 +58,8 @@ class MyRedisStorage(RedisStorage): ex=session.max_age, ) -class AuthAPI(AppLogger): +class AuthAPI: def __init__(self): - super().__init__() self.conf = getConfig() async def checkUserPermission(self, user, path): @@ -125,7 +124,7 @@ class AuthAPI(AppLogger): @web.middleware async def checkAuth(self,request,handler): - self.info(f'checkAuth() called ... {request.path=}') + info(f'checkAuth() called ... {request.path=}') t1 = time.time() path = request.path user = await auth.get_auth(request) @@ -136,17 +135,17 @@ class AuthAPI(AppLogger): try: ret = await handler(request) t3 = time.time() - self.info(f'timecost=client({ip}) {user} access {path} cost {t3-t1}, ({t2-t1})') + info(f'timecost=client({ip}) {user} access {path} cost {t3-t1}, ({t2-t1})') return ret except Exception as e: t3 = time.time() - self.info(f'Exception=client({ip}) {user} access {path} cost {t3-t1}, ({t2-t1}), except={e}') + info(f'Exception=client({ip}) {user} access {path} cost {t3-t1}, ({t2-t1}), except={e}') raise e if user is None: - self.info(f'timecost=client({ip}) {user} access need login to access {path} ({t2-t1})') + info(f'timecost=client({ip}) {user} access need login to access {path} ({t2-t1})') raise web.HTTPUnauthorized - self.info(f'timecost=client({ip}) {user} access {path} forbidden ({t2-t1})') + info(f'timecost=client({ip}) {user} access {path} forbidden ({t2-t1})') raise web.HTTPForbidden() async def needAuth(self,path): diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 888010d..5e6a060 100755 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -9,7 +9,7 @@ from aiohttp.web_response import Response, StreamResponse from appPublic.jsonConfig import getConfig from appPublic.dictObject import DictObject from appPublic.folderUtils import listFile -from appPublic.app_logger import AppLogger +from appPublic.log import info, debug, warning, error, critical, exception from .utils import unicode_escape from .serverenv import ServerEnv @@ -41,13 +41,12 @@ class ObjectCache: -class BaseProcessor(AppLogger): +class BaseProcessor: @classmethod def isMe(self,name): return name=='base' def __init__(self,path,resource): - super().__init__() self.env_set = False self.path = path self.resource = resource @@ -135,7 +134,7 @@ class BaseProcessor(AppLogger): return resp async def datahandle(self,request): - self.debug('*******Error*************') + debug('*******Error*************') self.content='' def setheaders(self): diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index 8269335..26872d2 100755 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -8,7 +8,7 @@ from aiohttp import web from appPublic.folderUtils import ProgramPath from appPublic.dictObject import DictObject from appPublic.jsonConfig import getConfig -from appPublic.app_logger import AppLogger +from appPublic.log import info, debug, warning, error, critical, exception from sqlor.dbpools import DBPools @@ -30,11 +30,10 @@ class AHApp(web.Application): def get_data(self, k): return self.data.get(k, DictObject()) -class ConfiguredServer(AppLogger): +class ConfiguredServer: def __init__(self, auth_klass=AuthAPI, workdir=None): self.auth_klass = auth_klass self.workdir = workdir - super().__init__() if self.workdir is not None: pp = ProgramPath() config = getConfig(self.workdir, diff --git a/ahserver/dbadmin.py b/ahserver/dbadmin.py index 23d647c..2073823 100755 --- a/ahserver/dbadmin.py +++ b/ahserver/dbadmin.py @@ -20,7 +20,7 @@ from sqlor.crud import CRUD from appPublic.dictObject import multiDict2Dict from appPublic.jsonConfig import getConfig -from appPublic.app_logger import AppLogger +from appPublic.log import info, debug, warning, error, critical, exception from .error import Error,Success actions = [ @@ -30,19 +30,19 @@ actions = [ "filter" ] -class DBAdmin(AppLogger): +class DBAdmin: def __init__(self, request,dbname,tablename, action): self.dbname = dbname self.tablename = tablename self.request = request self.action = action if action not in actions: - self.debug('action not defined:%s' % action) + debug('action not defined:%s' % action) raise HTTPNotFound try: self.crud = CRUD(dbname,tablename) except Exception as e: - self.info('e= %s' % e) + exception('e= %s' % e) traceback.print_exc() raise HTTPNotFound @@ -51,7 +51,7 @@ class DBAdmin(AppLogger): d = await self.crud.I() return json_response(Success(d)) except Exception as e: - self.debug('except=%s' % e) + exception('except=%s' % e) traceback.print_exc() return json_response(Error(errno='metaerror',msg='get metadata error')) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index a2d54fd..9c6f215 100755 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -38,7 +38,7 @@ from appPublic.i18n import getI18N from appPublic.dictObject import DictObject, multiDict2Dict from appPublic.timecost import TimeCost from appPublic.timeUtils import timestampstr -from appPublic.app_logger import AppLogger +from appPublic.log import info, debug, warning, error, critical, exception from .baseProcessor import getProcessor, BricksUIProcessor, TemplateProcessor from .baseProcessor import PythonScriptProcessor, MarkdownProcessor @@ -72,7 +72,7 @@ def i18nDICT(request): return json.dumps(i18n.getLangDict(l)).encode(c.website.coding) -class ProcessorResource(AppLogger, StaticResource,Url2File): +class ProcessorResource(StaticResource,Url2File): def __init__(self, prefix: str, directory: PathLike, *, name: Optional[str]=None, expect_handler: Optional[_ExpectHandler]=None, @@ -81,7 +81,6 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): append_version: bool=False, indexes:list=[], processors:dict={}) -> None: - AppLogger.__init__(self) StaticResource.__init__(self,prefix, directory, name=name, expect_handler=expect_handler, @@ -263,9 +262,12 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): self.y_env.i18n = serveri18n self.y_env.file_realpath = file_realpath self.y_env.redirect = redirect - self.y_env.info = self.info - self.y_env.error = self.error - self.y_env.debug = self.debug + self.y_env.info = info + self.y_env.error = error + self.y_env.debug = debug + self.y_env.warning = warning + self.y_env.critical = critical + self.y_env.exception = exception self.y_env.remember_user = remember_user self.y_env.forget_user = forget_user self.y_env.get_user = get_user @@ -289,7 +291,7 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): if config.website.dbadm and path.startswith(config.website.dbadm): pp = path.split('/')[2:] if len(pp)<3: - self.error('%s:not found' % str(request.url)) + error('%s:not found' % str(request.url)) raise HTTPNotFound dbname = pp[0] tablename = pp[1] @@ -299,7 +301,7 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): if config.website.dbrest and path.startswith(config.website.dbrest): pp = path.split('/')[2:] if len(pp)<2: - self.error('%s:not found' % str(request.url)) + error('%s:not found' % str(request.url)) raise HTTPNotFound dbname = pp[0] tablename = pp[1] @@ -311,7 +313,7 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): if config.website.download and path.startswith(config.website.download): pp = path.split('/')[2:] if len(pp)<1: - self.error('%s:not found' % str(request.url)) + error('%s:not found' % str(request.url)) raise HTTPNotFound dp = '/'.join(pp) path = path_decode(dp) @@ -328,7 +330,7 @@ class ProcessorResource(AppLogger, StaticResource,Url2File): if self.request_filename and os.path.isdir(self.request_filename): config = getConfig() if not config.website.allowListFolder: - self.error('%s:not found' % str(request.url)) + error('%s:not found' % str(request.url)) raise HTTPNotFound # print(f'{self.request_filename=}, {str(request.url)=} handle as a normal file') return await super()._handle(request) diff --git a/ahserver/proxyProcessor.py b/ahserver/proxyProcessor.py index 73a6c8b..c279418 100755 --- a/ahserver/proxyProcessor.py +++ b/ahserver/proxyProcessor.py @@ -1,4 +1,5 @@ import aiohttp +from appPublic.log import info, debug, warning, error, critical, exception from aiohttp import web, BasicAuth from aiohttp import client from .baseProcessor import * @@ -17,7 +18,7 @@ class ProxyProcessor(BaseProcessor): te = self.run_ns['tmpl_engine'] txt = await te.render(url,**ns) data = json.loads(txt) - self.debug('proxyProcessor: data=%s' % data) + debug('proxyProcessor: data=%s' % data) return data async def datahandle(self,request): @@ -44,7 +45,7 @@ class ProxyProcessor(BaseProcessor): await self.retResponse.prepare(request) async for chunk in res.content.iter_chunked(chunk_size): await self.retResponse.write(chunk) - self.debug('proxy: datahandle() finish') + debug('proxy: datahandle() finish') def setheaders(self):