forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
49 lines (43 loc) · 1.47 KB
/
logger.py
File metadata and controls
49 lines (43 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import logging.config
from graphql import GraphQLError
class GraphQLLogFilter(logging.Filter):
"""
Filter GraphQL errors that are intentional. See
https://github.com/graphql-python/graphene/issues/513
"""
def filter(self, record):
if record.exc_info:
etype, _, _ = record.exc_info
if etype == GraphQLError:
return None
if record.stack_info and "GraphQLError" in record.stack_info:
return None
if record.msg and "GraphQLError" in record.msg:
return None
if record.msg and "GraphQLLocatedError" in record.msg:
return None
if record.msg and "Traceback" in record.msg:
return None
return True
logger_dict = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {"console": {"level": "DEBUG", "class": "logging.StreamHandler",},},
# Prevent graphql exception from displaying in console
"filters": {"graphql_error_log_filter": {"()": GraphQLLogFilter,},},
"loggers": {
"graphql.execution.executor": {
"level": "WARNING",
"handlers": ["console"],
"filters": ["graphql_error_log_filter",],
},
"graphql.execution.utils": {
"level": "WARNING",
"handlers": ["console"],
"filters": ["graphql_error_log_filter",],
},
},
}
logging.config.dictConfig(logger_dict)
logger = logging.getLogger("TrackerAPI")