0
# --------------------------------------
# Start of logging of removed folders
# ----------------------------------------
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='RemovedCRMFolders.log',
                    filemode='w')


# -------------------------------------------
# Checks to see if listed folders exists and then deletes
# -------------------------------------------


def remove_directory(pathslist):
    for path in pathslist:
        if os.path.exists(path) and os.path.isdir(path):
            shutil.rmtree(path)
            logging.warning('Found ' + path + ' removing')
            print(colored('Found ' + path + ' removing', 'green'))
        else:
            print('Looking for ' + path + ' not found..')

dirs_to_delete = [
    'C:\Folder1',
    'C:\Folder2'
    ]

would using both the logging.warning and print underneath be a way to still show the output in console/window if it finds a folder? Right now if you write the code without print and just logging.warning it will no longer print to console stating it sees the folder and will just write to the log file and I am looking to have it show in console and still print to log is there a easier way to do this within the logging command or is this the best way?

Jason Lucas
  • 113
  • 9
  • The `logging` documentation has [relevant examples](https://docs.python.org/3/howto/logging-cookbook.html#logging-to-multiple-destinations). – glibdud Feb 14 '19 at 21:19
  • Possible duplicate of [Printing to screen and writing to a file at the same time](https://stackoverflow.com/questions/9321741/printing-to-screen-and-writing-to-a-file-at-the-same-time) – glibdud Feb 14 '19 at 21:21

1 Answers1

0
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='RemovedCRMFolders.log',
                    filemode='w')

here you have specified your logs to go to RemovedCRMFolders.log. your logs are being written in that file. you won't see your output in console. to see your output in console you need to remove filename when you're configuring your logger.

Asav Patel
  • 1,113
  • 1
  • 7
  • 25