我想生成带有时间戳的日志代替我提到的弹出窗口。 请建议生成带时间戳的日志的一些步骤。
代码: -
click("1450851018693.png")
wait(2)
click(Pattern("1450851091319.png").targetOffset(1,2))
click(Pattern("1450851555941.png").targetOffset(-201,1))
type("111")
click(Pattern("1450851201892.png").targetOffset(-13,2))
type("121")
wait(1)
if exists ("1450851253342.png"):
popup("start button is enabled")
click("1450851253342.png")
在上面的代码而不是弹出窗口中,我希望将消息记录在带有时间戳的文件中。 请帮助..
答案 0 :(得分:1)
您可以使用Python中的logging
模块导入它并获取记录器实例:
import logging
FORMAT='%(asctime)-15s %(message)s'
logging.basicConfig(format=FORMAT)
logger=logging.getLogger('')
然后,在您的代码中使用它(默认情况下,级别info
不会打印到控制台,但是warning
是)
logger.warning('My message')
你应该有一个日志条目:
2016-03-07 13:10:43,451我的留言
有关说明和基本教程,请参阅Logging Python。