File tree Expand file tree Collapse file tree
api/graphql/types/reservation_units Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import logging
2+
13import graphene
24from auditlog .models import LogEntry
35from django .conf import settings
46from graphene_django .rest_framework .mutation import SerializerMutation
57from graphql import GraphQLError
68
79from api .graphql .extensions .legacy_helpers import OldAuthSerializerMutation
8- from api .graphql .types .reservation_units .permissions import (
9- ReservationUnitPermission ,
10- )
10+ from api .graphql .types .reservation_units .permissions import ReservationUnitPermission
1111from api .graphql .types .reservation_units .serializers import (
1212 ReservationUnitCreateSerializer ,
1313 ReservationUnitUpdateSerializer ,
1414)
15- from api .graphql .types .reservation_units .types import (
16- ReservationUnitType ,
17- )
15+ from api .graphql .types .reservation_units .types import ReservationUnitType
1816from opening_hours .errors import HaukiAPIError , HaukiRequestError
1917from opening_hours .utils .hauki_resource_hash_updater import HaukiResourceHashUpdater
2018from reservation_units .models import (
2119 ReservationUnit ,
2220)
23- from tilavarauspalvelu .utils import logging
2421
2522logger = logging .getLogger (__name__ )
2623
Original file line number Diff line number Diff line change 1+ import logging
12from typing import Any
23
34from django .core .management .base import BaseCommand
45
56from opening_hours .utils .hauki_resource_hash_updater import HaukiResourceHashUpdater
6- from tilavarauspalvelu .utils .logging import getLogger
77
8- logger = getLogger (__name__ )
8+ logger = logging . getLogger (__name__ )
99
1010
1111class Command (BaseCommand ):
Original file line number Diff line number Diff line change 11import datetime
22import json
3+ import logging
34from typing import NotRequired , TypedDict , Unpack
45
56from django .conf import settings
1213 HaukiAPIResource ,
1314 HaukiAPIResourceListResponse ,
1415)
15- from tilavarauspalvelu .utils import logging
1616
1717__all__ = [
1818 "HaukiAPIClient" ,
Original file line number Diff line number Diff line change 1+ import logging
12from datetime import datetime , time
23
34from django .utils import timezone
89from opening_hours .utils .hauki_api_client import HaukiAPIClient
910from opening_hours .utils .hauki_api_types import HaukiAPIResource , HaukiAPIResourceListResponse
1011from opening_hours .utils .reservable_time_span_client import ReservableTimeSpanClient
11- from tilavarauspalvelu .utils .logging import getLogger
1212
13- logger = getLogger (__name__ )
13+ logger = logging . getLogger (__name__ )
1414
1515DEFAULT_TIMEZONE = get_default_timezone ()
1616
Original file line number Diff line number Diff line change 1+ import logging
2+ from pathlib import Path
3+
4+ BASE_PATH = str (Path (__file__ ).resolve ().parent .parent )
5+
6+
7+ class TVPFormatter (logging .Formatter ):
8+ def format (self , record ):
9+ self ._style ._defaults = {"dotpath" : self .get_dotpath (record )}
10+ return super ().format (record )
11+
12+ def get_dotpath (self , record : logging .LogRecord ) -> str :
13+ """Try to fetch the full dot import path for the module the log happened at."""
14+ # For library logs
15+ split_path = record .pathname .split ("site-packages" )
16+ if len (split_path ) > 1 :
17+ return self .format_dotpath (split_path [- 1 ][1 :])
18+
19+ # For our logs
20+ split_path = record .pathname .split (str (BASE_PATH ))
21+ if len (split_path ) > 1 :
22+ return self .format_dotpath (split_path [- 1 ][1 :])
23+
24+ # Fall back to the module name, which doesn't include the full path info
25+ return record .module
26+
27+ @staticmethod
28+ def format_dotpath (path : str ) -> str :
29+ return path .removesuffix (".py" ).replace ("/" , "." ).replace ("\\ " , "." )
Original file line number Diff line number Diff line change 1010from helusers import defaults
1111from sentry_sdk .integrations .django import DjangoIntegration
1212
13- from .utils .logging import getLogger
14-
1513# This is a temporary fix for graphene_permissions to avoid ImportError when importing ResolveInfo
1614# This can be removed when graphene_permissions is updated to import ResolveInfo from the correct package.
1715graphql .ResolveInfo = graphql .GraphQLResolveInfo
340338 "filters" : {},
341339 "formatters" : {
342340 "common" : {
343- "format" : "{asctime} | {levelname} | {module}.{funcName}:{lineno} | {message}" ,
341+ "()" : "tilavarauspalvelu.logging.TVPFormatter" ,
342+ "format" : "{asctime} | {levelname} | {dotpath}.{funcName}:{lineno} | {message}" ,
344343 "datefmt" : "%Y-%m-%dT%H:%M:%S%z" ,
345344 "style" : "{" ,
346345 },
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments