Save log to application folder

Asked

Viewed 48 times

1

Hello, I made an application and added log (logging), but it is saving in the root folder '/', and I want you to save in the root folder of the application Monitor/, how do I.

logging.basicConfig(filename= 'Log.txt', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(funcName)s => %(message)s')
logging.info('INICIO DO PROGRAMA...') 

1 answer

0


How you just set the file as Log.txt it will save you the directory where you started the application, the simplest way to solve the problem is

    from os import path
    # ...
    log_file = path.join(path.dirname(path.realpath(__file__)),"Log.txt")
    logging.basicConfig(filename=log_file, ...) ```

This will take the directory where the program to compose the log file path.

  • It worked, thank you very much!.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.