diff --git a/app/log.py b/app/log.py new file mode 100644 index 0000000..4b1f79a --- /dev/null +++ b/app/log.py @@ -0,0 +1,8 @@ +import logging + + +log = logging.getLogger('root') +log.setLevel(logging.ERROR) # DEBUG > INFO > WARNING > ERROR > CRITICAL +logging.basicConfig( + format='[%(asctime)s] %(levelname)s @ %(module)s.%(funcName)s()#%(lineno)d: %(message)s' + ) diff --git a/app/main.py b/app/main.py index ef4ccba..85fd563 100644 --- a/app/main.py +++ b/app/main.py @@ -15,8 +15,15 @@ from sqlalchemy.exc import IntegrityError, OperationalError from . import config from .lib_general import * +from .log import * from .routers import items, users, websockets +#log = logging.getLogger('root') +#log.setLevel(logging.ERROR) # DEBUG > INFO > WARNING > ERROR > CRITICAL +#logging.basicConfig( + #format='[%(asctime)s] %(levelname)s @ %(module)s.%(funcName)s()#%(lineno)d: %(message)s' + #) + app = FastAPI() @@ -90,4 +97,24 @@ async def add_process_time_header(request: Request, call_next): async def get_root(): print(config.settings.APP_NAME) + log.setLevel(logging.DEBUG) + + print('***') + log.debug('This is debug') # 10 DEBUG + log.info('This is info') # 20 INFO + log.warn('This is warn') # 30 WARNING + log.warning('This is a warning') # 30 WARNING + log.error('This is an error') # 40 ERROR + log.exception('This is an exception') # 40 ERROR + log.critical('This is critical') # 50 CRITICAL + #print('----') + #logging.debug('This is debug') # 10 DEBUG + #logging.info('This is info') # 20 INFO + #logging.warn('This is warn') # 30 WARNING + #logging.warning('This is a warning') # 30 WARNING + #logging.error('This is an error') # 40 ERROR + #logging.exception('This is an exception') # 40 ERROR + #logging.critical('This is critical') # 50 CRITICAL + print('^^^') + return {'hello': 'This is the Aether API using FastAPI.'} diff --git a/app/routers/users.py b/app/routers/users.py index 6055086..ee67cfe 100644 --- a/app/routers/users.py +++ b/app/routers/users.py @@ -4,6 +4,7 @@ from pydantic import BaseModel, EmailStr, Field from typing import Dict, List, Optional, Set, Union from ..lib_general import * +from ..log import * from app.config import settings from app.db import * from app.redis import * @@ -94,8 +95,24 @@ async def list_users(): """ Get a list of users """ + log.setLevel(logging.DEBUG) + log.debug(str(locals().keys())+' | '+str(locals().values())) + log.debug(locals()) + + #log.setLevel(logging.INFO) + #log.info(None) + + log.setLevel(logging.WARNING) + + print('***') + log.debug('This is debug') # 10 DEBUG + log.info('This is info') # 20 INFO + log.warn('This is warn') # 30 WARNING + log.warning('This is a warning') # 30 WARNING + log.error('This is an error') # 40 ERROR + log.exception('This is an exception') # 40 ERROR + log.critical('This is critical') # 50 CRITICAL - print(settings.APP_NAME) users = [{'username': 'test.user.1'}, {'username': 'test.user.2'}, {'username': 'Scott.Idem'}]