Adding in logging
This commit is contained in:
8
app/log.py
Normal file
8
app/log.py
Normal 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'
|
||||
)
|
||||
27
app/main.py
27
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.'}
|
||||
|
||||
@@ -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'}]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user