-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Eduard Kaverinskyi <[email protected]>
- Loading branch information
1 parent
88141fb
commit 5629342
Showing
13 changed files
with
146 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,4 +107,7 @@ venv.bak/ | |
*.db | ||
|
||
# Logs | ||
*.log | ||
*.log | ||
|
||
# Database files | ||
*.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export APP_DB_URL="postgresql://whohacks:S3cret@localhost:5432/whohacks" | ||
export OAUTH_OPENID="http://sso.hsp.sh/auth/realms/hsp/.well-known/openid-configuration" | ||
export OAUTH_CLIENT_ID="fake-development-client-id" | ||
export LOGLEVEL="DEBUG" # DEBUG | INFO | WARNING | ERROR | ||
env | grep APP_ > .env | ||
env | grep OUATH_ > .env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
import os | ||
|
||
loggers = {} | ||
|
||
def get_loglevel(loglevel: str): | ||
match loglevel: | ||
case "DEBUG": | ||
loglevel = logging.DEBUG | ||
case "INFO": | ||
loglevel = logging.INFO | ||
case "WARNING": | ||
loglevel = logging.WARNING | ||
case "ERROR": | ||
loglevel = logging.ERROR | ||
case "CRITICAL": | ||
loglevel = logging.CRITICAL | ||
case _: | ||
loglevel = logging.INFO | ||
|
||
return loglevel | ||
|
||
|
||
def init_logger(name: str) -> logging.Logger: | ||
if loggers.get(name): | ||
return loggers[name] | ||
|
||
logger = logging.getLogger(name) | ||
loglevel = get_loglevel(os.environ.get("LOGLEVEL")) | ||
|
||
formatter = logging.Formatter( | ||
fmt=f"({name}) %(asctime)s %(module)s %(levelname)s: %(message)s", | ||
datefmt="%m/%d/%Y %I:%M:%S %p", | ||
) | ||
|
||
for handler in logger.handlers: | ||
logger.removeHandler(handler) | ||
|
||
stream_handler = logging.StreamHandler() | ||
stream_handler.setFormatter(formatter) | ||
file_handler = logging.FileHandler(f"{name}.log") | ||
file_handler.setFormatter(formatter) | ||
|
||
logger.addHandler(stream_handler) | ||
logger.addHandler(file_handler) | ||
|
||
logger.setLevel(loglevel) | ||
|
||
loggers[name] = logger | ||
|
||
return logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.