"""
Logging configuration
"""

import logging
import os
from logging.handlers import RotatingFileHandler


def setup_logging(app):
    """Setup application logging"""
    if not app.debug and not app.testing:
        # Production logging setup
        if not os.path.exists('logs'):
            os.mkdir('logs')
        
        file_handler = RotatingFileHandler(
            'logs/pets_powerwashing.log',
            maxBytes=10240,
            backupCount=10
        )
        file_handler.setFormatter(logging.Formatter(
            '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
        ))
        file_handler.setLevel(logging.INFO)
        app.logger.addHandler(file_handler)
        
        app.logger.setLevel(logging.INFO)
        app.logger.info('Pets of Powerwashing startup')
    else:
        # Development logging
        app.logger.setLevel(logging.DEBUG)