Fix Python – Using python Logging with AWS Lambda

As the AWS documentation suggests:
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def my_logging_handler(event, context):
logger.info(‘got event{}’.format(event))
logger.error(‘something went wrong’)

Now I made:
import logging
logging.basicConfig(level = logging.INFO)
logging.info(“Hello World!”)

The first snip….

Fix Python – Python/Django: log to console under runserver, log to file under Apache

How can I send trace messages to the console (like print) when I’m running my Django app under manage.py runserver, but have those messages sent to a log file when I’m running the app under Apache?
I reviewed Django logging and although I was impressed with its flexibility and configurability for advanced uses, I’m still stumped with how to handle….

Fix Python – Set logging levels

I’m trying to use the standard library to debug my code:
This works fine:
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info(‘message’)

I can’t make work the logger for the lower levels:
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.info(‘message’)

loggi….

Fix Python – How to log all sql queries in Django?

How can I log all SQL queries that my django application performed?
I want to log everything, including SQLs from admin site. I saw this question and a FAQ answer but I still can’t figure out where should I put
from django.db import connection
connection.queries

to log everything to one file?
So my question is – what should I do to have a file (….

Fix Python – logging.info doesn’t show up on console but warn and error do

When I log an event with logging.info, it doesn’t appear in the Python terminal.
import logging
logging.info(‘I am info’) # no output

In contrast, events logged with logging.warn do appear in the terminal.
import logging
logging.warn(‘I am warning’) # outputs “I am warning”

Is there a environment level change I can to make logging.info print t….

Fix Python – How do I add custom field to Python log format string?

My current format string is:
formatter = logging.Formatter(‘%(asctime)s : %(message)s’)

and I want to add a new field called app_name which will have a different value in each script that contains this formatter.
import logging
formatter = logging.Formatter(‘%(asctime)s %(app_name)s : %(message)s’)
syslog.setFormatter(formatter)
logger.addHandler….

Fix Python – How to configure logging to syslog in Python?

I can’t get my head around Python’s logging module. My needs are very simple: I just want to log everything to syslog. After reading documentation I came up with this simple test script:
import logging
import logging.handlers

my_logger = logging.getLogger(‘MyLogger’)
my_logger.setLevel(logging.DEBUG)

handler = logging.handlers.SysLogHandler()

m….