从Bash脚本运行的Python脚本未记录日志

从Bash脚本运行的Python脚本未记录日志,python,linux,bash,shell,logging,Python,Linux,Bash,Shell,Logging,我有一个bash脚本,它在每次系统启动时运行一个python脚本 python脚本的一部分应该记录到日志文件(主要用于调试目的)。无论是手动运行还是通过bash脚本运行,脚本都运行良好 问题是,当我通过bash脚本运行它时,Python脚本不会创建日志文件,也不会记录脚本中的任何调试日志命令 我假设这是目录中的权限问题 我正在从/etc/rc.local调用我的脚本 sudo /home/user/python_scripts/go.sh & 下面是我的bash脚本(go.sh)中的p

我有一个bash脚本,它在每次系统启动时运行一个python脚本

python脚本的一部分应该记录到日志文件(主要用于调试目的)。无论是手动运行还是通过bash脚本运行,脚本都运行良好

问题是,当我通过bash脚本运行它时,Python脚本不会创建日志文件,也不会记录脚本中的任何调试日志命令

我假设这是目录中的权限问题

我正在从/etc/rc.local调用我的脚本

sudo /home/user/python_scripts/go.sh &
下面是我的bash脚本(go.sh)中的python行

在我的python代码中,我使用以下方法记录日志(当我手动运行时,会将日志文件放在python_scripts目录中):

import logging

daily_log = 'log-' + str(time.strftime("%m-%d-%y")) + '.log'

logging.basicConfig(format='%(asctime)s (%(levelname)s) - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filename=daily_log,level=logging.DEBUG)

logging.debug(' Debug Message - Error 1241')

尝试使用日志文件的整个路径。脚本运行时,它将登录到工作目录

如果从/home/user/python\u scripts/运行,它将把文件放在那里


如果从/home运行,文件将位于您的主目录中。

发布写入文件的部分。
bash
脚本如何运行?Python脚本是写入特定文件还是仅写入标准错误和/或输出(它继承自
bash
脚本,可能与手动运行Python时不同)?更新了更多信息…您是否签出了ans?具体来说,将记录器设置为
logging.StreamHandler(sys.stdout)
import logging

daily_log = 'log-' + str(time.strftime("%m-%d-%y")) + '.log'

logging.basicConfig(format='%(asctime)s (%(levelname)s) - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filename=daily_log,level=logging.DEBUG)

logging.debug(' Debug Message - Error 1241')