PyQt5接口处理日志数据到文件,特别适合多线程程序。

dvg-pyqt-filelogger的Python项目详细描述


https://img.shields.io/pypi/v/dvg-pyqt-fileloggerhttps://img.shields.io/pypi/pyversions/dvg-pyqt-fileloggerRequirements Statushttps://img.shields.io/badge/code%20style-black-000000.svghttps://img.shields.io/badge/License-MIT-purple.svg

DvG_PyQt_文件记录器

PyQt5接口来处理日志数据到文件,特别适合于 多线程程序。

安装:

pip install dvg-pyqt-filelogger

美国石油学会

class FileLogger(write_header_function: Callable = None, write_data_function: Callable = None)

Bases: ^{tt2}$

Handles logging data to a file particularly well suited for multithreaded programs where one thread is writing data to the log and the other thread (the main/GUI thread) requests starting and stopping of the log, e.g., by the user pressing a button.

The methods ^{tt3}$, ^{tt4}$ and ^{tt5}$ can be directly called from the main/GUI thread.

In the logging thread you repeatedly need to call ^{tt6}$. This method takes cares of the state machine behind ^{tt7}$ and will perform the appropiate action, such as creating a file on disk, creating the header or writing new data to the log.

Args:
write_header_function (^{tt8}$, optional):

Reference to a function that contains your specific code to write a header to the log file. This will get called during ^{tt6}$.

Default: ^{tt10}$

write_data_function (^{tt8}$, optional):

Reference to a function that contains your specific code to write new data to the log file. This will get called during ^{tt6}$.

Default: ^{tt10}$

Both of the above functions can contain calls to the following class members:

  • ^{tt14}$
  • ^{tt15}$
注意:
这个类缺少互斥体,因此从一开始就不是线程安全的。 只要update()在另一个互斥体内被调用,比如 例如,作为数据采集互斥体,它是安全的。
注意:
根据设计,当发生异常时,此类中的代码将继续运行。 它们被报告到命令行。

信号:

signal_recording_started (str)

新录制开始时发出。例如,对。, 更新记录按钮的文本。在

返回:
新创建的日志文件的文件路径为str
类型:
PyQt5.QtCore.pyqtSignal()
signal_recording_stopped (pathlib.Path)

在录制停止时发出。有助于,例如,更新 记录按钮的文本。在

返回:
新创建的日志文件的文件路径为pathlib.Path()。 例如,您可以使用它自动导航到登录 或要求用户输入“保存到”目标。
类型:
PyQt5.QtCore.pyqtSignal()

用法示例:

^{pr2}$

方法

  • set_write_header_function(write_header_function: Callable)

  • set_write_data_function(write_data_function: Callable)

  • record(state: bool = True)

    可以从任何线程调用。在

  • start_recording()

    可以从任何线程调用。在

  • stop_recording()

    可以从任何线程调用。在

  • update(filepath: str = "", mode: str = "a")

    必须重复调用此方法,大概是在 需要记录日志的线程,例如,数据生成线程。 此方法负责FileLogger和后面的状态机 将执行适当的操作,例如在磁盘上创建文件, 正在创建标头或将新数据写入日志。在

    参数:
    文件路径(str):

    必须创建或打开的日志文件的位置 用于写入访问。在

    默认值:"{yyMMdd_HHmmss}.txt",表示当前日期和时间。在

    模式(str,可选):
    打开日志文件的模式,请参见open() 更多细节。最常见的选择:

    • ^{tt34}$: Open for writing, truncating the file first.
    • ^{tt35}$: Open for writing, appending to the end of the file if it exists.

    默认值:a

  • write(data: AnyStr) -> bool
    将二进制或ASCII数据写入当前打开的日志文件。通过 设计此方法中发生的任何异常都不会终止 执行,但它将向命令行报告错误并继续 改为打开。在

    如果成功,则返回True,否则返回False。在

  • flush()

    一旦 可能。不要重复调用,因为这会导致开销。在

  • close()

  • is_recording() -> bool

  • elapsed() -> float

    返回自开始录制以来的时间(以秒为单位)(float)。在

  • pretty_elapsed() -> str

    以“h:mm:ss”(str)的形式返回录制开始后的时间。在

变更日志

  • 关于PyPI的第一次发布

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从远程安卓应用程序打开/关闭嵌套   java在每个请求上获取memcache变量导致问题   如何在java中使用itext获取pdf文件的标题   java如何使用firebase令牌发送通知?   java不能在spring数据聚合中包含嵌套字段   用于调度作业的java Cron表达式   java当我使用TabActivity 安卓时,TabActivity类型已被弃用   加密Java Bouncy Castle加密使用AES加密   awt Java,将GUI与ActionListener类分离   如何在Java中创建一个根据输入返回枚举的方法?   java什么是Gxt 3.1.1实现对话框的方法。Gxt 3.0.0是否支持getHideButton()?   java如何解决构建错误?   java XWPF POI如何设置段落中的文本而不使用换行符