Skip to content

Commit 51b8c39

Browse files
committed
Add set_log_level function
1 parent 2e004c6 commit 51b8c39

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/cloud_tasks_deferred/deferred.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ def do_something_later(key, amount):
7575
from __future__ import unicode_literals
7676

7777
import datetime
78+
import logging
7879
import os
7980
import pickle
8081
import types
8182

8283
from google.cloud import tasks_v2
8384
from google.protobuf import timestamp_pb2
8485

86+
_DEFAULT_LOG_LEVEL = logging.INFO
8587
_DEFAULT_URL = '/_tasks/deferred'
8688
_DEFAULT_QUEUE = 'default'
8789

@@ -102,6 +104,17 @@ class InvalidTaskError(Error):
102104
"""The parameters, headers, or method of the task is invalid."""
103105

104106

107+
def set_log_level(log_level): # pragma: no cover
108+
"""Sets the log level deferred will log to in normal circumstances.
109+
110+
Args:
111+
log_level: one of logging log levels, e.g. logging.DEBUG,
112+
logging.INFO, etc.
113+
"""
114+
global _DEFAULT_LOG_LEVEL
115+
_DEFAULT_LOG_LEVEL = log_level
116+
117+
105118
def run(data):
106119
"""Unpickle and execute a task.
107120

src/cloud_tasks_deferred/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def abort(status):
3636
for k, v in six.iteritems(environ)
3737
if k.upper().startswith('HTTP_X_APPENGINE_')
3838
]
39-
logger.info(', '.join(headers))
39+
logger.log(deferred._DEFAULT_LOG_LEVEL, ', '.join(headers))
4040

4141
content_length = int(environ.get('CONTENT_LENGTH', 0))
4242
data = environ['wsgi.input'].read(content_length)

0 commit comments

Comments
 (0)