I am running Django application on Google App Engine standard env. I have two services running for dev and prod. both services plus my local machine are configured with Google Logging Client for logging. Recently, for some reason, the prod service stopped posting logs into StackDriver. But both my local and dev service are posting logs.
here is my code:
settings.py
from google.cloud import logging
if os.getenv('GAE_APPLICATION', None):
client = logging.Client()
else:
# setup for my local logging.
client = logging.Client.from_service_account_json('PATH TO JSON FILE')
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'stackdriver': {
'level': 'INFO',
'class': 'google.cloud.logging.handlers.CloudLoggingHandler',
'client': client
},
'console':{
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'mail_admins': {
'level': 'CRITICAL',
'class': 'django.utils.log.AdminEmailHandler',
"email_backend": "anymail.backends.mailgun.EmailBackend"
}
},
'loggers': {
'django': {
'handlers': ['stackdriver'],
'propagate': True,
'level': 'INFO',
},
'django.request': {
'handlers': ['stackdriver', 'console', 'mail_admins'],
'level': 'INFO',
'propagate': True,
},
} }
urls.py
def trigger_error(request):
import logging
logger = logging.getLogger('stackdriver')
logger.error('test error')
logger.critical('test critical')
logger.warning('test warning')
logger.info('test info')
division_by_zero = 1 / 0
path('debug/', trigger_error),
My questions are:
- Is there any limits or quotes for logging into a specific service? if so, how to check if my prod service exhausted these limits?
- Is there anything else I can do to debug this issue?
thanks!
EDIT:
I made some progress. I changed the client and handler to logging_v2, added root and empty loggers, and removed an old logger no longer exists.
if os.getenv('GAE_APPLICATION', None):
client = google.cloud.logging_v2.Client()
else:
client = google.cloud.logging_v2.Client.from_service_account_json('PATH TO JSON FILE')
client.setup_logging()
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'stackdriver': {
'level': 'INFO',
'class': 'google.cloud.logging_v2.handlers.CloudLoggingHandler',
'client': client,
'formatter': 'verbose'
},
'console':{
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple'
}
},
'loggers': {
'': {
'level': 'INFO',
'handlers': ['stackdriver', 'console'],
'propagate': True
},
'root': {
'level': 'INFO',
'handlers': ['stackdriver', 'console'],
'propagate': True
},
'django': {
'handlers': ['stackdriver', 'console'],
'propagate': True,
'level': 'INFO'
},
'django.request': {
'handlers': ['stackdriver', 'console'],
'level': 'INFO',
'propagate': True
},
}
}
now logs are showing up in the service logs but missing severity.