Skip to content

Instantly share code, notes, and snippets.

View sakku116's full-sized avatar
💭
studiying

Zakky sakku116

💭
studiying
View GitHub Profile
@sakku116
sakku116 / python-logging-format.py
Created November 18, 2022 04:33
format logging output in python logging
import logging
# set config in main file
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)s\t| %(message)s',
datefmt='%d/%m/%Y %H:%M:%S',
)
# create logger instead using logging directly

how to migrate database into another database

  • dump the current db of django project settings
    python manage.py dumpdata > dbdump.json
    
  • Change the database settings to new database
  • run migrate command to set up the new database *if the new database does not have same model (tables), as when creating new database
    python manage.py migrate
    
import threading
from typing import TypeVar, Generic, Callable, Any
T = TypeVar("T")
class ThreadWithResult(threading.Thread, Generic[T]):
# "https://stackoverflow.com/a/65447493/17881894"
"""
function renderPostsCallback(pages_total = 1, current_page = 1, has_previous = false, has_next = false) {
/* control frontend pagination */
let max = 5
if (pages_total < 5) {
max = pages_total
}
let max_left = 2
if (current_page<3) {
max_left = current_page-1
}
import uvicorn
from uvicorn.config import LOGGING_CONFIG
# default uvicorn format
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "%(asctime)s %(levelprefix)s %(message)s"
LOGGING_CONFIG["formatters"]["default"]["datefmt"] = "%Y-%m-%d %H:%M:%S"
# api call format
LOGGING_CONFIG["formatters"]["access"]["fmt"] = '%(asctime)s %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s'
LOGGING_CONFIG["formatters"]["access"]["datefmt"] = "%Y-%m-%d %H:%M:%S"
from uvicorn.config import LOGGING_CONFIG
import logging
# custom logging
LOGGING_CONFIG["loggers"]["uvicorn.custom"] = {
"handlers": ["custom"],
"level": "INFO",
"propagate": False
}
LOGGING_CONFIG["handlers"]["custom"] = {
def generatePathsFromDictBasedPaths(d: dict, **kwargs):
"""
the point is just adding prefix to each key,
then call self function to proccess nested dict.
example:
```
{
"dashboard": {},
"help": {},