if DEBUG:
    logging.basicConfig(level=logging.DEBUG, format=
        '%(asctime)s %(levelname)s %(message)s')
else:
    logging.basicConfig(level=logging.DEBUG, format=
        '%(asctime)s %(levelname)s %(message)s', filename=
        '/my_log_file.log', filemode='a')
Python/Django: log to console under runserver, log to file under Apache