创建/实施Python脚本记录系统以远程查看日志的最佳方法是什么
对不起,标题令人费解。我将尝试将其分解。
我最近获得了Raspberry Pi,我想构建和实现半体外的方法,以检查我的Python脚本的状态而不会出现。我已经构建了一个将日志添加到HTML文件中的小系统,然后将HTML文件局部置于LocalHosthost,因此我可以在不介入Raspberry Pi的情况下检查一下,但是目前,此方法并不十分干净。如果我想在记录系统中添加更多程序,我将不得不将代码复制并粘贴到其他程序中,这真的很笨拙。
我正在寻找一种使我的记录系统能够一次处理多个脚本的方法,而无需复制和粘贴代码。我的最终目标是使过程是自动的,我将在脚本中内置的记录方法上启动一个脚本,并且我的网站会自动添加一个新按钮,当按下时,将我带给我的日志。特定的Python程序。
我不是要您为我编码,而是要提供实施此想法的最佳方法。我应该构建一个可以导入所有文件的模块吗?托管网站的Python脚本将如何接收日志?
我现在意识到,当我要输入这个问题时,很难解释或可视化我要做的事情,我先前道歉。
sorry for the convoluted title. I will try to break it down.
I've recently gotten a Raspberry Pi and I want to build and implement a half decent method to check the status of my python scripts without SSHing. I've already built a little system that has logs added to an HTML file and then the HTML file is localhosted so I can check in without SSHing in to the Raspberry Pi, but currently this method isn't very clean. If I wanted to add more programs to the logging system i would have to copy and paste the code over to the other programs and it would just be really janky.
I am looking for a way to make my logging system able to handle multiple scripts at once and without copy and pasting code. My end goal is to have the process be automatic, I would start a script on the raspberry pi with the logging method built into the script, and my website would automatically add a new button that, when pressed, brings me to the logs of that specific python program.
I'm not asking you to code it for me, I'm asking for the best way to implement this idea. Should I build a module that I can import into all of my files? How would the python script that hosts the website receive the logs?
I realize now as I'm typing this question out that it is really hard to explain or visualize what I am trying to do, I apologize in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来这是Python模块的好用例。如果您已经编写了代码以将脚本记录到HTML文件中,请使用该代码并将其制成自己的模块。然后,您可以将该模块导入到其他Python脚本中。
然后..
您可以根据脚本名称将记录模块写入文件名,并具有一些其他功能,这些函数可以使用链接到其他页面的按钮生成您的“索引”页面。可以根据文件目录列表完成生成。
甚至更好,请使用诸如NGINX之类的东西简单地提供HTML日志文件中的路径的静态索引。
It sounds like this is a good use case for Python modules. If you already have written the code to write a scripts logs to an HTML file, simply take that code and make it it's own module. Then you can import that module into your other python scripts.
and then..
You can have your logging module write to a filename based on the script name, and have some other function that generates your "index" page with buttons that link to those other pages. The generation can be done based on a directory listing of files.
Or even better, use something like Nginx to simply serve a static index of the path where your HTML log files live.