import os
from datetime import datetime
from media_transporter import config

script_path = '%s/../' % os.path.dirname(os.path.abspath(__file__))
"""string: path to script being executed."""


class Logger():
    """Responsible for logging messages from the script and writing to disk."""
    @staticmethod
    def log(text):
        """Static method to open a log file and write messages generated by
        the script.

        Parameters
        ----------
        text
            Message to log

        Returns
        -------
        None
        """
        dt = datetime.now()
        with open('%s/%s' % (script_path, config.logfile), 'a') as fh:
            fh.write('[%s] %s\n' % (dt.strftime('%Y-%m-%d %H:%M:%S'), text))
        print '[%s] %s' % (dt.strftime('%Y-%m-%d %H:%M:%S'), text)
