相关疑难解决方法(0)

如何使用自定义日志记录处理程序将记录器重定向到wxPython textCtrl?

我在我的python应用程序中使用了一个模块,该模块使用日志记录模块编写了大量消息.最初我在控制台应用程序中使用它,并且很容易使用控制台处理程序将日志记录输出显示在控制台上.现在我使用wxPython开发了我的应用程序的GUI版本,我想将所有日志输出显示到自定义控件 - 多行textCtrl.有没有办法我可以创建一个自定义日志记录处理程序,以便我可以重定向所有日志记录输出并显示日志消息,无论我想要什么/在这种情况下,wxPython应用程序.

python logging wxpython

11
推荐指数
2
解决办法
9483
查看次数

如何在Python日志记录模块中抑制换行符.

我想取消换行符,例如log.info("msg").当我们"打印"它时

print msg,
Run Code Online (Sandbox Code Playgroud)

所以我需要像昏迷这样的东西来记录.

我播下这个问题 在Python日志模块中抑制换行, 但是任何人都可以给我参考或者像"Hello world"这样的简单例子谢谢!

python logging

11
推荐指数
2
解决办法
7386
查看次数

将 Python 的控制台输出重定向到 Dash

如何重定向/显示控制台输出(包括我在程序中打印的输出),以便它出现在 Dash 应用程序中(在用户看到的屏幕上)?

python plotly plotly-dash

5
推荐指数
1
解决办法
4808
查看次数

如何使用Python的Logging模块写入日志文件中的上一行?

这里的长期潜伏者,终于摆脱了木制品.

基本上,我正在尝试做的是让我的记录器将这样的数据写入日志文件:

Connecting to database . . . Done.
Run Code Online (Sandbox Code Playgroud)

我想要'连接数据库'...'在调用函数时写入,并在函数成功执行后写入'完成'.

我正在使用Python 2.6和日志记录模块.另外,我真的很想避免使用装饰器.非常感激任何的帮助!

python logging

3
推荐指数
2
解决办法
1176
查看次数

记录某些内容时如何调用 Python 函数

我正在使用日志记录库,并且我想在记录任何事件时调用一个函数。像这样的东西:

import logging

#logging config here

async def on_log(message, level): #call this whenever something is logged
    print(level, ":", message)

logging.debug("Hello world")
Run Code Online (Sandbox Code Playgroud)

编辑:on_log是一个协程

Edit2:我尝试实现您的建议之一,但我不能 100% 确定如何将其添加到我当前的日志记录配置中。

from logging import *
import datetime
import sys

class MyLogger(Handler):
    def emit(*args):
        for item in args:
            print(item)

time = datetime.datetime.today()
logtime = f"{time.year}-{time.month}-{time.day}__{time.hour}h-{time.minute}m-{time.second}s"

file_handler = FileHandler(filename=f'./logs/{logtime}.log')  # File output
stdout_handler = StreamHandler(sys.stdout)  # Console output

basicConfig(
    format=f'[%(asctime)s][%(levelname)s] %(message)s',
    datefmt='%H:%M:%S',
    level=DEBUG,
    handlers=[file_handler, stdout_handler, MyLogger]
)
Run Code Online (Sandbox Code Playgroud)

我收到此错误: AttributeError: type object 'MyLogger' has no attribute 'formatter'

python logging

0
推荐指数
1
解决办法
1775
查看次数

标签 统计

python ×5

logging ×4

plotly ×1

plotly-dash ×1

wxpython ×1