Skip to content

Commit

Permalink
better logging, also logging into a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Anay-Joshi26 committed Jan 13, 2025
1 parent 8655bdc commit afb7c05
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
.env
pinpoint.db
perthpinpoint.log
3 changes: 2 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
# Enabled, Disabled if "DEV" True

##### PROD OPTIONS #####
uvicorn_LOGGING = "error"
uvicorn_LOGGING = "info"
uvicorn_HOST = "0.0.0.0"
uvicorn_PORT = 8080
uvicorn_WORKERS = 4
uvicorn_ACCESSLOG = True
LOGS_FILENAME = "perthpinpoint.log"
##### PROD OPTIONS #####

# Development
Expand Down
15 changes: 15 additions & 0 deletions app/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@

if BANNER:
print(f"{pp_banner}")

print(LOGGING_CONFIG)

# add a file
LOGGING_CONFIG["handlers"]["file"] = {
"class": "logging.FileHandler",
"filename": LOGS_FILENAME,
"formatter": "default",
"level": "INFO",
}

LOGGING_CONFIG["loggers"]["uvicorn"]["handlers"].append("file")
LOGGING_CONFIG["loggers"]["uvicorn.error"]["handlers"] = ["file"]
#LOGGING_CONFIG["loggers"]["uvicorn.error"]["handlers"].append("file")
LOGGING_CONFIG["loggers"]["uvicorn.access"]["handlers"].append("file")

# why is this not done by default
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "%(asctime)s [%(name)s] %(levelprefix)s %(message)s"
Expand Down

0 comments on commit afb7c05

Please sign in to comment.