Adding in logging

This commit is contained in:
Scott Idem
2020-09-14 17:49:25 -04:00
parent d3b6f46368
commit 6bee9c19cf
3 changed files with 53 additions and 1 deletions

8
app/log.py Normal file
View File

@@ -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'
)

View File

@@ -15,8 +15,15 @@ from sqlalchemy.exc import IntegrityError, OperationalError
from . import config from . import config
from .lib_general import * from .lib_general import *
from .log import *
from .routers import items, users, websockets 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() app = FastAPI()
@@ -90,4 +97,24 @@ async def add_process_time_header(request: Request, call_next):
async def get_root(): async def get_root():
print(config.settings.APP_NAME) 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.'} return {'hello': 'This is the Aether API using FastAPI.'}

View File

@@ -4,6 +4,7 @@ from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union from typing import Dict, List, Optional, Set, Union
from ..lib_general import * from ..lib_general import *
from ..log import *
from app.config import settings from app.config import settings
from app.db import * from app.db import *
from app.redis import * from app.redis import *
@@ -94,8 +95,24 @@ async def list_users():
""" """
Get a list of 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'}] users = [{'username': 'test.user.1'}, {'username': 'test.user.2'}, {'username': 'Scott.Idem'}]