import logging
import psycopg2


def create_connection(host, dbname, user, password, port=5432):
    """
    Return psycopg2 connection

    https://www.psycopg.org/

    Parameters
    ----------
    host : str
        Database host address
    dbname : str
        Database name
    user : str
        User used to authenticate
    password : str
        Password used to authenticate
    port : int, optional
        Connection port number, by default 5432

    Returns
    -------
    connection
    """

    connection = None
    try:
        connection_string = (
            f"host={host} port={port} dbname={dbname} user={user} password={password}"
        )
        connection = psycopg2.connect(connection_string)
        logging.info("PostgreSQL database connected ...")
    except psycopg2.OperationalError as e:
        logging.info(f"{e}")
    return connection