flux0987
flux0987

Reputation: 87

where the logs are stored if logger = logging.getLogger(__name__)

I have set logger = logging.getLogger(__name__)

and using it like below:

def get_token(self, username, password):
        auth = HTTPBasicAuth(username, password)
        logging.info("%s" % self.base_url)
        try:
            response = requests.post(self.base_url, auth=auth, verify=False)
        except Exception as e:
            logging.error("%s" % str(e))

in which directory should i see the logs ?

Upvotes: 1

Views: 1509

Answers (1)

Beliaev Maksim
Beliaev Maksim

Reputation: 1647

you can specify two outputs: console (stream) and file output:

settings_folder = os.path.join(os.environ["APPDATA"], "my_app")
logging_file = os.path.join(settings_folder, "app.log")

if not os.path.isdir(settings_folder):
    os.mkdir(settings_folder)

# add logging to console and log file
logging.basicConfig(filename=logging_file, format='%(asctime)s (%(levelname)s) %(message)s', level=logging.DEBUG,
                    datefmt='%d.%m.%Y %H:%M:%S')
logging.getLogger().addHandler(logging.StreamHandler())

Upvotes: 2

Related Questions