How can I log both successful and failed login and logout attempts in Django?

You could hook up to the provided signals: django.contrib.auth.signals Recording to log import logging from django.contrib.auth.signals import user_logged_in, user_logged_out, user_login_failed from django.dispatch import receiver log = logging.getLogger(__name__) @receiver(user_logged_in) def user_logged_in_callback(sender, request, user, **kwargs): # to cover more complex cases: # http://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django ip = request.META.get(‘REMOTE_ADDR’) log.debug(‘login user: {user} via ip: {ip}’.format( user=user, ip=ip )) @receiver(user_logged_out) def … Read more

Adding python logging to FastApi endpoints, hosted on docker doesn’t display API Endpoints logs

Inspired by JPG’s answer, but using a pydantic model looked cleaner. You might want to expose more variables. This config worked good for me. from pydantic import BaseModel class LogConfig(BaseModel): “””Logging configuration to be set for the server””” LOGGER_NAME: str = “mycoolapp” LOG_FORMAT: str = “%(levelprefix)s | %(asctime)s | %(message)s” LOG_LEVEL: str = “DEBUG” # … Read more

How to log exceptions occurring in a django celery task

The question: I’d like Celery to catch exceptions and write them to a log file instead of apparently swallowing them… The current top answer here is so-so for purposes of a professional solution. Many python developers will consider blanket error catching on a case-by-case basis a red flag. A reasonable aversion to this was well-articulated … Read more

How to see the logs of a docker container

The first point you need to print your logs to stdout. To check docker logs just use the following command: docker logs –help Usage: docker logs [OPTIONS] CONTAINER Fetch the logs of a container Options: –details Show extra details provided to logs -f, –follow Follow log output –help Print usage –since string Show logs since … Read more

IIS 7 Log Request Body

It can actually be done, according to https://serverfault.com/a/90965 The IIS logs only record querystring and header information without any POST data. If you’re using IIS7, you can enabled Failed Request Tracing for status code 200. That will record all of the data and you can select which type of data to include.

tech