You're browsing snippets anonymously. Log in or create an account to save and manage your own snippets.
Public Snippets
Showing
5 snippets
using
language:
Python
Reset default python log handlers
import logging
formatter = logging.Formatter('FOO: %(message)s')
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
# This is the key line that removes the double logging
...
By
xtream1101
•
•
Updated
2025-03-04 18:33
Django graphene mutation input validation
import graphene
class ScratchpadMutation(graphene.relay.ClientIDMutation):
class Input:
created_by = graphene.String(required=True)
foobar = graphene.String()
test = g...
By
xtream1101
•
•
Updated
2025-02-06 14:13
Try, try again - Multiple try/except blocks in a flat format
data = {'some_key': 'key value'}
key_data = None
for _ in range(1):
try:
key_data = data['someKey']
except Exception: pass
else: break # It worked
try:
key_d...
By
xtream1101
•
•
Updated
2025-02-06 13:43
Multi key sort on a list of dicts
data = [
{'name': 'Alice', 'age': 25, 'city': 'New York'},
{'name': 'Bob', 'age': 30, 'city': 'London'},
{'name': 'Charlie', 'age': 20, 'city': 'New York'}
]
# Sort by 'city' first,...
By
xtream1101
•
•
Updated
2025-02-06 13:27
Showing
5 snippets
Snippet
import logging
formatter = logging.Formatter('FOO: %(message)s')
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
# This is the key line that removes the double logging
root_logger.handlers.clear()
# Must add a custom logger back otherwise there will be no log output
sys_stream = logging.StreamHandler()
sys_stream.setFormatter(formatter)
root_logger.addHandler(sys_stream)
logger = logging.getLogger(__name__)
Description
AWS lambdas seem to add their own custom logging to the python logger, causing all logs to output twice when also adding your own custom logger. You may not see any change when running this locally, but it does make a difference when running in a aws lambda.
By
xtream1101
•
•
Updated
2025-03-04 18:33