# Path: gsshapy/util/metadata.py
# def version():
#     return '2.3.9'


import logging
import appdirs
import os
from .metadata import version

def log_to_file(status=True, filename=default_log_file, level=None):
    """Log events to a file.

    Args:
        status (bool, Optional, Default=True)
            whether logging to file should be turned on(True) or off(False)
        filename (string, Optional, Default=None) :
            path of file to log to
        level (string, Optional, Default=None) :
            level of logging; whichever level is chosen all higher levels will be logged.
            See: https://docs.python.org/2/library/logging.html#levels
      """

    if status:
        if level is not None:
            logger.setLevel(level)

        try:
            os.mkdir(os.path.dirname(filename))
        except OSError:
            pass

        file_handler = logging.FileHandler(filename)
        # create formatter
        formatter = logging.Formatter('%(asctime)s - %(levelname)s-%(name)s: %(message)s')
        # add formatter to handler
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)


# Path: gsshapy/util/metadata.py
# def version():
#     return '2.3.9'


# Path: gsshapy/util/log.py
import logging
import appdirs
import os
from .metadata import version


def log_to_file(status=True, filename=default_log_file, level=None):
    """Log events to a file.

    Args:
        status (bool, Optional, Default=True)
            whether logging to file should be turned on(True) or off(False)
        filename (string, Optional, Default=None) :
            path of file to log to
        level (string, Optional, Default=None) :
            level of logging; whichever level is chosen all higher levels will be logged.
            See: https://docs.python.org/2/library/logging.html#levels
      """

    if status:
        if level is not None:
            logger.setLevel(level)

        try:
            os.mkdir(os.path.dirname(filename))
        except OSError:
            pass

        file_handler = logging.FileHandler(filename)
        # create formatter
        formatter = logging.Formatter('%(asctime)s - %(levelname)s-%(name)s: %(message)s')
        # add formatter to handler
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)


        logger.info("GSSHApy {0}".format(version()))