Logging and Monitoring

sessions.py
import logging

def establish_session(user_id)
  logging.info("Establishing session for user: {}".format(user_id))

  user = find_user(user_id)

  if not user:
    logging.error("Unable to find user {}!".format(user_id))
    raise UserNotFoundException(user_id)

  login_user(user)

  logging.info("Established session for user: {}".format(user_id))
  logging.debug("Last logged in: {}".format(user.last_login_time))

  return user
tail -f ./application.log
12:59:41.2 INFO  sessions.py: Establishing session for user: 3892
12:59:41.8 ERROR sessions.py: Unable to find user 3892!
12:59:43.2 INFO  sessions.py: Establishing session for user: 94012
12:59:43.8 INFO  sessions.py:19 Established session for user: 94012
12:59:43.8 DEBUG sessions.py:21 Last logged in: 3 days ago