Ach113
Ach113

Reputation: 1825

Python logging does not write to file

I am trying to log some data to a local file like so:

import logging

# dont know if format parameter is really necessary here
logging.basicConfig(filename='logs/server_logs.log', filemode='a', format='%(message)s') 

logging.info("some data")

This code did generate 0 kb "server_logs.log" file, but it stays empty, no text gets appended to it. Am I doing something wrong?

Upvotes: 2

Views: 251

Answers (1)

Mayank Porwal
Mayank Porwal

Reputation: 34046

You need to set this:

logger = logging.getLogger()
logger.setLevel(logging.INFO)

Upvotes: 6

Related Questions