
import os
import logging
import datetime

from website import settings


def format_now():
    return datetime.datetime.now().isoformat()


def add_file_logger(logger, script_name, suffix=None):
    _, name = os.path.split(script_name)
    if suffix is not None:
        name = '{0}-{1}'.format(name, suffix)
    file_handler = logging.FileHandler(
        os.path.join(
            settings.LOG_PATH,
            '.'.join([name, format_now(), 'log'])
        )
    )
    logger.addHandler(file_handler)


import os
import logging
import datetime

from website import settings


def format_now():
    return datetime.datetime.now().isoformat()


def add_file_logger(logger, script_name, suffix=None):
    _, name = os.path.split(script_name)
    name = name.rstrip('c')
    if suffix is not None:
        name = '{0}-{1}'.format(name, suffix)
    file_handler = logging.FileHandler(
        os.path.join(
            settings.LOG_PATH,
            '.'.join([name, format_now(), 'log'])
        )
    )
    logger.addHandler(file_handler)

Make script log file names more consistent
Make script log file names more consistent

...by stripping c's of filenames, so that we get
script_name.py-timestamp rather than script_name.pyc-timestamp

  
  import os
  import logging
  import datetime
  
  from website import settings
  
  
  def format_now():
      return datetime.datetime.now().isoformat()
  
  
  def add_file_logger(logger, script_name, suffix=None):
      _, name = os.path.split(script_name)
+     name = name.rstrip('c')
      if suffix is not None:
          name = '{0}-{1}'.format(name, suffix)
      file_handler = logging.FileHandler(
          os.path.join(
              settings.LOG_PATH,
              '.'.join([name, format_now(), 'log'])
          )
      )
      logger.addHandler(file_handler)
  
Make script log file names more consistent
## Code Before:

import os
import logging
import datetime

from website import settings


def format_now():
    return datetime.datetime.now().isoformat()


def add_file_logger(logger, script_name, suffix=None):
    _, name = os.path.split(script_name)
    if suffix is not None:
        name = '{0}-{1}'.format(name, suffix)
    file_handler = logging.FileHandler(
        os.path.join(
            settings.LOG_PATH,
            '.'.join([name, format_now(), 'log'])
        )
    )
    logger.addHandler(file_handler)

## Instruction:
Make script log file names more consistent
## Code After:

import os
import logging
import datetime

from website import settings


def format_now():
    return datetime.datetime.now().isoformat()


def add_file_logger(logger, script_name, suffix=None):
    _, name = os.path.split(script_name)
    name = name.rstrip('c')
    if suffix is not None:
        name = '{0}-{1}'.format(name, suffix)
    file_handler = logging.FileHandler(
        os.path.join(
            settings.LOG_PATH,
            '.'.join([name, format_now(), 'log'])
        )
    )
    logger.addHandler(file_handler)
