I am trying to add timestamp details to log message getting printed.
From This:
DEBUG:crate.client.http:Sending request to /_sql? ...
INFO:reporter.reporter:Notification successfully processed
To This:
[2020-07-15 10:41:41.568+00] DEBUG:crate.client.http:Sending request to /_sql? ...
[2020-07-15 10:41:42.102+00] INFO:reporter.reporter:Notification successfully processed
So, I added asctime format in basicconfig part of my code by adding format='[%(asctime)s %(message)s',datefmt='%m/%d/%Y %I:%M:%S %p]:
def log():
r = EnvReader(log=logging.getLogger(__name__).info)
level = r.read(StrVar('LOGLEVEL', 'INFO')).upper()
logging.basicConfig(level=level,
format='[%(asctime)s %(message)s',datefmt='%m/%d/%Y %I:%M:%S %p]')
return logging.getLogger(__name__)
Also, the part after change giving output as:
[08/10/2020 07:47:06 AM] Env variable QL_DEFAULT_DB not set, using default value of: crate
[08/10/2020 07:47:06 AM] Backend selected for tenant 'None' is: crate
[08/10/2020 07:47:06 AM] Env variable CRATE_HOST set to , using this value.
[08/10/2020 07:47:06 AM] Env variable CRATE_PORT not set, using default value of: 4200
[08/10/2020 07:47:06 AM] Env variable KEEP_RAW_ENTITY not set, using default value of: False
[08/10/2020 07:47:06 AM] Env variable LOGLEVEL not set, using default value of: INFO
[08/10/2020 07:47:06 AM] Notification successfully processed
x.x.x.x - - [10/Aug/2020 07:47:06] "POST /v2/notify HTTP/1.1" 200 -
[08/10/2020 07:47:06 AM] - - [10/Aug/2020 07:47:06] "POST /v2/notify HTTP/1.1" 200 -
So the problem is that i want millisecond to also get printed with it in the format like this : [2020-07-15 10:41:41.568+00]
How can i use millisecond to print with asctime or any other way to print timestamp in python?
Any help on this will be appreciable.