- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
当我输入这个命令时出现这个错误:
$ python3.4 cron_e2e.py -f test_web_events -E ctg-clickstream testbrad
错误:
$ python3.4 cron_e2e.py -f test_web_events -E ctg-clickstream testbrad
Traceback (most recent call last):
File "cron_e2e.py", line 421, in <module>
sys.exit(main(sys.argv))
File "cron_e2e.py", line 368, in main
log.addHandler(logging.FileHandler(logfile))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/__init__.py", line 1006, in __init__
StreamHandler.__init__(self, self._open())
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/__init__.py", line 1030, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/bli1/Development/QE/chun-qe-trinity-functional/qe/tests/qe/logs/testbrad_8_21_2015_cron.log'
错误发生在这一行:
log.addHandler(logging.FileHandler(logfile))
不太确定我的代码在哪里没有为我创建日志文件
代码:
def main(argv):
"Test"
exit_code = 0
global me; me = os.path.basename(argv[0]) # name of this program
global mydir; mydir = os.path.dirname(os.path.abspath(__file__))
parser = argparse.ArgumentParser(description=main.__doc__)
parser.add_argument("-f", "--functional_test", metavar="FUNCTEST",
dest="functest", help="Type of functional test")
parser.add_argument("-p","--phase", action="append",
metavar="POST|HDFS|HIVE|ALL", dest="phase",
help="phase of test to run")
parser.add_argument("-t", "--testfile", metavar="TESTFILE",
dest="testfile", default=os.path.join(mydir, "resources/cron.json"),
help="file with test commands")
parser.add_argument("-E","--Event", metavar="EVENTNAME",
dest="event_names", action="append",
help="[repeatable] topic to which to post")
parser.add_argument("runtag",
metavar="RUNTAG",
help="run tag for this run")
args = parser.parse_args(args=argv[1:]) # will exit on parse error
log = logging.getLogger(me)
log.setLevel(logging.INFO)
dt = datetime.datetime.utcnow()
logfile = "qe/logs/" + (args.runtag + "_{}_{}_{}".format(dt.month, dt.day, dt.year) + "_cron.log")
pdb.set_trace()
if isinstance(logfile, str):
if os.path.exists(logfile):
os.remove(logfile)
# logging.FileHandler() returns FileHandler class, the file is opened and used as the stream for logging
log.addHandler(logging.FileHandler(logfile))
console = logging.StreamHandler(sys.stderr); console.setLevel(logging.WARNING); log.addHandler(console)
最佳答案
问题是您定义要转到的日志文件的目录 - "qe/logs/"
- 不存在。
默认模式为 FileHandler
是 'a'
,这意味着如果日志文件存在,它会打开它并在末尾开始附加到它,否则它会创建文件。
但是 FileHandler 只会在日志文件不存在时创建日志文件,如果目录不存在则不会创建目录,如果目录不存在,它会像您遇到的那样抛出错误。
您需要自己手动或以编程方式创建目录。如果要以编程方式创建目录,可以使用 - os.makedirs()
- 这会 -
create all intermediate-level directories needed to contain the leaf directory.
例子-
import os, os.path
if not os.path.exists("qe/logs/"):
os.makedirs("qe/logs/")
关于python - 记录器找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32133856/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!