0

Hi I want my python script to print minute wise log so I want variable b to be replaced but its not happening and log file generating with name %(b)s_python.log

Please Help !

import logging, datetime

a=datetime.date.today()

b=a.strftime("%y_%B_%a_%H%M")

print(b)

logging.basicConfig(filename="D:\%(b)s_python.log",level=logging.DEBUG,format="%(levelname)s %(asctime)s-%(message)s")

logging.debug("Hi Sudhirrrrrrrrr")
3
  • You will need a special logging handler for that. See the docs about logging handlers for details. Commented Dec 23, 2018 at 7:20
  • you'll need to specify the %b in the format section and not the filename. Commented Dec 23, 2018 at 8:04
  • Did you try filename="D:\{0}_python.log".format(b),level=logging.DEBUG,format="{0} {1}-{2}".format(levelname, asctime, message)? Commented Dec 23, 2018 at 9:54

1 Answer 1

1

datetime.date.today() does not give you the current hour and minute.

import logging, datetime
a=datetime.datetime.now()
b='D:\\'+a.strftime("%y_%B_%a_%H%M")+'s_python.log'
print(b)
logging.basicConfig(filename=b,level=logging.DEBUG,format="%(levelname)s %(asctime)s-%(message)s")
logging.debug("Hi Sudhirrrrrrrrr")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.