Skip to content

Commit

Permalink
Merge pull request #25 from jaypyles/24-add-log-level-switch
Browse files Browse the repository at this point in the history
feat: add log level option in env vars
  • Loading branch information
jaypyles authored Jul 28, 2024
2 parents 144b362 + c17b7d6 commit f3a9003
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ scraperr:

scraperr_api:
environment:
- LOG_LEVEL=INFO
- MONGODB_URI=mongodb://root:example@webscrape-mongo:27017 # used to access MongoDB
- SECRET_KEY=your_secret_key # used to encode authentication tokens (can be a random string)
- ALGORITHM=HS256 # authentication encoding algorithm
Expand Down
43 changes: 29 additions & 14 deletions api/backend/app.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
# STL
import os
import uuid
import logging
import traceback
from io import BytesIO
from openpyxl import Workbook
from typing import Optional

# PDM
from fastapi import BackgroundTasks, Depends, FastAPI, HTTPException
from fastapi import Depends, FastAPI, HTTPException, BackgroundTasks
from openpyxl import Workbook
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse, StreamingResponse
from fastapi.middleware.cors import CORSMiddleware
import docker
from api.backend.schemas import User

from api.backend.auth.auth_utils import get_current_user

client = docker.from_env()

# LOCAL
import docker
from api.backend.job import (
average_elements_per_link,
get_jobs_per_day,
query,
insert,
delete_jobs,
update_job,
delete_jobs,
get_jobs_per_day,
average_elements_per_link,
)
from api.backend.models import (
UpdateJobs,
DownloadJob,
SubmitScrapeJob,
DeleteScrapeJobs,
UpdateJobs,
)
from api.backend.schemas import User
from api.backend.auth.auth_utils import get_current_user
from api.backend.auth.auth_router import auth_router
import traceback

client = docker.from_env()


def get_log_level(level_name: Optional[str]) -> int:
level = logging.INFO

if level_name:
level_name = level_name.upper()
level = getattr(logging, level_name, logging.INFO)

return level


log_level = os.getenv("LOG_LEVEL")
LOG_LEVEL = get_log_level(log_level)

logging.basicConfig(
level=logging.INFO,
level=LOG_LEVEL,
format="%(levelname)s: %(asctime)s - %(name)s - %(message)s",
handlers=[logging.StreamHandler()],
)
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
context: .
dockerfile: docker/api/Dockerfile
environment:
- LOG_LEVEL=INFO
- MONGODB_URI=mongodb://root:example@webscrape-mongo:27017 # used to access MongoDB
- SECRET_KEY=your_secret_key # used to encode authentication tokens (can be a random string)
- ALGORITHM=HS256 # authentication encoding algorithm
Expand Down

0 comments on commit f3a9003

Please sign in to comment.